我把数据库的值帮定在datagrid上了,里面用了模版列(textBox),(textBox)值修改后怎么保存到数据库中?我的连接数据库代码在类里面,不知道怎么保存请高手帮忙!
连接和帮定代码:
public class DataBase
{
private string strSQL;
//与SQL Server的连接字符串设置
private string connectionString = "server=(local);uid=sa;pwd=;database=Electricity";
//与数据库的连接
private SqlConnection myConnection;
private DataSet ds = new DataSet();//实例化

private SqlDataAdapter da;
   
public DataBase()
{
}
//** 描  述:连接操作数据库函数
//****************************************************************
public DataSet SelectDataBase(string tempStrSQL, string tempTableName)
{
        
{
this.strSQL = tempStrSQL;
this.myConnection = new SqlConnection(connectionString);
this.da = new SqlDataAdapter(this.strSQL, this.myConnection);
this.ds.Clear();
this.da.Fill(ds, tempTableName);
return ds;//返回填充了数据的DataSet,其中数据表以tempTableName给出的字符串命名
}
}在调用类的代码:
protected void database()
{
DataBase link = new DataBase();
this.ds = link.SelectDataBase(sendStrSQL, sendTableName);
}
绑定DataGrid1代码:
sendTableName="ClassScore1";
sendStrSQL="select * from ClassScore1";
database();
this.DataGrid1.DataKeyField = "ClassScoreId";
this.DataGrid1.DataSource=ds;
this.DataGrid1.DataBind();
急!!!!!!!!!!在线等!!

解决方案 »

  1.   

    把Textbox的值再取出来就好了啊然后更新
      

  2.   

    通过FindControl来找到控件然后取值
      

  3.   

    http://adandelion.cnblogs.com/archive/2005/11/12/274505.htmlLabel lblName = (Label) e.Item.FindControl("LblName");
    LinkButton  lbtn = (LinkButton) e.Item.FindControl("LbtnEdit");
    Label lbl = (Label) (e.Item.FindControl("LblId"));
    ---
    差不多就是上面的写法,改一下类型就可以了!
      

  4.   

    RowUpdated?TextBox txt = (TextBox) e.Item.FindControl("txtBox1");
    string str=txt.Text;
      

  5.   

    应该是
    TextBox txt = (TextBox) e.Item.Cells[0].FindControl("txtBox1");
    string str=txt.Text;
      

  6.   

    1。    TextBox TxtName=(TextBox)e.Item.FindControl("FirstName");//FirstName html里定义的模版控件2。 string FirstName=TxtName.Text.ToString();3。执行sql语句  更新FirstName里的数据4。重新邦定datagrid
      

  7.   

    1。    TextBox TxtName=(TextBox)e.Item.FindControl("FirstName");//FirstName html里定义的模版控件2。 string FirstName=TxtName.Text.ToString();3。加个事务批量执行sql语句  更新FirstName里的数据4。重新邦定datagrid