private void Page_Load(object sender, System.EventArgs e)
{
myConnection=new SqlConnection("workstation id=CHENPENGCHENG;packet size=4096;user id=sa;password=85225926;data s" +
"ource=chenpengcheng;persist security info=False;initial catalog=毕业设计");
BindGrid();// 在此处放置用户代码以初始化页面
}
public void Data_edit(object sender,DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=(int)e.Item.ItemIndex;
BindGrid();
}
public void Data_cancer(object sender,DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=-1;
BindGrid();
}
public void Data_update(object sender,DataGridCommandEventArgs E)
{
string update="update d141 set ip地址=@ip地址,工作状态=@工作状态,房间号=@房间号,连接交换机=@连接交换机,连接端口号=@连接端口号 where 端口号=@端口号";
SqlCommand myCommand=new SqlCommand(update,myConnection);
myCommand.Parameters.Add(new SqlParameter("@端口号",SqlDbType.Int,10));
myCommand.Parameters.Add(new SqlParameter("@ip地址",SqlDbType.Char,10));
myCommand.Parameters.Add(new SqlParameter("@工作状态",SqlDbType.Char,10));
myCommand.Parameters.Add(new SqlParameter("@房间号",SqlDbType.Char,10));
myCommand.Parameters.Add(new SqlParameter("@连接交换机",SqlDbType.Char,15));
myCommand.Parameters.Add(new SqlParameter("@连接端口号",SqlDbType.Char,15));
myCommand.Parameters["@端口号"].Value=1;
String[] cols={"@ip地址","@工作状态","@房间号","@连接交换机","@连接端口号"};
int numCols=E.Item.Cells.Count;
for(int i=1;i<numCols-1;i++)
{
String colvalue=((TextBox)E.Item.Cells[i+1].Controls[0]).Text;
myCommand.Parameters[cols[i-1]].Value=colvalue;
}
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
BindGrid();
}
public void BindGrid()
{
SqlDataAdapter myCommand1=new SqlDataAdapter("select 端口号,ip地址,工作状态,房间号,连接交换机,连接端口号 from d141",myConnection);
//myCommand1.SelectCommand.Parameters.Add(new SqlParameter("@端口号",SqlDbType.Int,4));
DataSet ds=new DataSet();
myCommand1.Fill(ds,"d141");
DataGrid1.DataSource=ds.Tables["d141"].DefaultView;
DataGrid1.DataBind();
}
为什么我始终不能更新,输入数据后不变,如果把String colvalue=((TextBox)E.Item.Cells[i+1].Controls中的i+1改为i的话,只要一点更新所有的值跟着第一个数据的值变,如果是i+1的话,点更新无用,为什么?望达人指点
{
myConnection=new SqlConnection("workstation id=CHENPENGCHENG;packet size=4096;user id=sa;password=85225926;data s" +
"ource=chenpengcheng;persist security info=False;initial catalog=毕业设计");
BindGrid();// 在此处放置用户代码以初始化页面
}
public void Data_edit(object sender,DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=(int)e.Item.ItemIndex;
BindGrid();
}
public void Data_cancer(object sender,DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=-1;
BindGrid();
}
public void Data_update(object sender,DataGridCommandEventArgs E)
{
string update="update d141 set ip地址=@ip地址,工作状态=@工作状态,房间号=@房间号,连接交换机=@连接交换机,连接端口号=@连接端口号 where 端口号=@端口号";
SqlCommand myCommand=new SqlCommand(update,myConnection);
myCommand.Parameters.Add(new SqlParameter("@端口号",SqlDbType.Int,10));
myCommand.Parameters.Add(new SqlParameter("@ip地址",SqlDbType.Char,10));
myCommand.Parameters.Add(new SqlParameter("@工作状态",SqlDbType.Char,10));
myCommand.Parameters.Add(new SqlParameter("@房间号",SqlDbType.Char,10));
myCommand.Parameters.Add(new SqlParameter("@连接交换机",SqlDbType.Char,15));
myCommand.Parameters.Add(new SqlParameter("@连接端口号",SqlDbType.Char,15));
myCommand.Parameters["@端口号"].Value=1;
String[] cols={"@ip地址","@工作状态","@房间号","@连接交换机","@连接端口号"};
int numCols=E.Item.Cells.Count;
for(int i=1;i<numCols-1;i++)
{
String colvalue=((TextBox)E.Item.Cells[i+1].Controls[0]).Text;
myCommand.Parameters[cols[i-1]].Value=colvalue;
}
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
BindGrid();
}
public void BindGrid()
{
SqlDataAdapter myCommand1=new SqlDataAdapter("select 端口号,ip地址,工作状态,房间号,连接交换机,连接端口号 from d141",myConnection);
//myCommand1.SelectCommand.Parameters.Add(new SqlParameter("@端口号",SqlDbType.Int,4));
DataSet ds=new DataSet();
myCommand1.Fill(ds,"d141");
DataGrid1.DataSource=ds.Tables["d141"].DefaultView;
DataGrid1.DataBind();
}
为什么我始终不能更新,输入数据后不变,如果把String colvalue=((TextBox)E.Item.Cells[i+1].Controls中的i+1改为i的话,只要一点更新所有的值跟着第一个数据的值变,如果是i+1的话,点更新无用,为什么?望达人指点
解决方案 »
- VS2010安装不了 看看各位谁遇到过这种蛋疼的问题啊!
- EF 多线程多表更新的问题
- 如何将filesysteminfo对象绑定到gridview
- string.Empty与""有什么区别?
- 求一个表达式,限定输入字符数量的。
- 重开帖:根据div位置调整web form位置,内附代码
- 十万火急!!!系统正式投入使用,但是SqlConnection满了,卡死了……怎么办?
- 要做一个电子商务交易平台ASP.NET
- 一个类型转换的问题,好人进来看看阿 我的确没有分了
- 在外企的朋友们?有没有较详细的美国IP地址分配表可以分享的?
- 怎么动态的控制DataList 显示的列数?(没分,求你帮忙)
- [老题新问]如何在输入全角中文的情况下限制textarea的最大输入长度?(解决就结贴)
{
String colvalue=((TextBox)E.Item.Cells[i].Controls[0]).Text;
myCommand.Parameters[cols[i]].Value=colvalue;
}
{
String colvalue=((TextBox)E.Item.Cells[i].Controls[1]).Text;
//E.Item.Cells[i].Controls[1]改成
myCommand.Parameters[cols[i]].Value=colvalue;
}
myCommand.Parameters[cols[i-1]].Value=colvalue;
{
String colvalue=((TextBox)E.Item.Cells[i].Controls[0]).Text;
myCommand.Parameters[cols[i]].Value=colvalue;
}
谁知道E.Item.Cells[i].Controls[0]返回的是什么值呢?
写在
(!IsPostBack)
{
BindGrid();
}