2013-10-04 26 views

回答

0
public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     string connetionString = null; 
     SqlConnection connection ; 
     SqlCommand command ; 
     SqlDataAdapter adapter = new SqlDataAdapter(); 
     DataSet ds = new DataSet(); 
     DataView dv ; 
     string sql = null; 
     connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"; 
     sql = "Select * from product"; 
     connection = new SqlConnection(connetionString); 
     try 
     { 
      connection.Open(); 
      command = new SqlCommand(sql, connection); 
      adapter.SelectCommand = command; 
      adapter.Fill(ds, "Add New"); 
      adapter.Dispose(); 
      command.Dispose(); 
      connection.Close(); 

      dv = new DataView(ds.Tables[0]); 
      DataRowView newRow = dv.AddNew(); 
      newRow["Product_ID"] = 7; 
      newRow["Product_Name"] = "Product 7"; 
      newRow["Product_Price"] = 111; 
      newRow.EndEdit(); 
      dv.Sort = "product_id"; 


      dataGridView1.DataSource = dv; 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show (ex.ToString()); 
     } 
    } 
} 
0

試試這個:

要找到您要使用的數據網格$ .find()

var MyGrid=$.find(<%=myGrid.ClientID%>)