@id只是一个string类型的实例
string sql="select a,b,e,f,g frome a,b where id=ID and id=@id";
改为
string sql="select a,b,e,f,g frome a,b where id=ID and id=+"@id;
string sql="select a,b,e,f,g frome a,b where id=ID and id=@id";
改为
string sql="select a,b,e,f,g frome a,b where id=ID and id=+"@id;
现在要把a.b,a.e,b.f,b.j导入到数据表c{a,b,e,f,g}中。
前台页面是利用一个datagrid控件把a表和b表的一些字段显示出来,比如:
a b e f g 操作
2 3 5 3 2 导入
3 2 5 6 3 导入
5 3 3 3 3 导入
控件里有一个“导入”按钮,当点击“导入”按钮时便把该行记录导入到c表。
这是我的一些代码:
public void DataGrid1_daoru(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string @id=DataGrid1.DataKeys[(int)e.Item.ItemIndex].ToString();string sql="select a,b,e,f,g frome a,b where a.e=b.e and id=@id";
mycom =new SqlCommand(sql,mycon);
myreader = mycom.ExecuteReader();
while (myreader.Read())
{
string @a,@b,@e,@f,@g;
@a= Convert.ToString(myreader["a"]).Trim();
@b = Convert.ToString(myreader["b"]).Trim();
@e= Convert.ToString(myreader["e"]).Trim();
@f = Convert.ToString(myreader["f"]).Trim();
@g = Convert.ToString(myreader["g"]).Trim();
}
String sql1 ="insert into c(a,b,e,f,g) values(@a,@b,@e,@f,@g)";
SqlCommand mycom1 = new SqlCommand(sql1,mycon);
}
可老是报错:
必须声明变量 '@id'
各位大虾帮忙解决一下,在线等候!
id和ID都不是自动编号,而是一些字符。
怎么没人理我啊!!
有出错:
必须声明变量 '@a'
并且每个变量都要初始化
怎样设置呢?