这段代码错在哪里?
SqlConnection conn = new SqlConnection(@ "server=CAOJUN\SQLEXPRESS;database=caojuntest;uid=sa;pwd=sa ");
conn.Open();
SqlCommand cmd = new SqlCommand( "select * from part where part_id=@part_id ", conn);
SqlParameter par = new SqlParameter( "@part_id ",SqlDbType.Int);
par.Value = GridView1.SelectedValue;
cmd.Parameters.Add(par);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
为什么执行到da.Fill(ds)时报没有提供@part_id参数???????????????
------解决方案--------------------改为这样
SqlConnection conn = new SqlConnection(@ "server=CAOJUN\SQLEXPRESS;database=caojuntest;uid=sa;pwd=sa ");
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter cmd = new SqlDataAdapter( "select * from part where part_id=@part_id ", conn);
ds.SelectCommand.Parameters.Add( "@part_id ", GridView1.SelectedValue);
da.Fill(ds);