所以我将 Gridview 与 WCF 一起使用。我已经设法从文本框插入到 gridiview,但现在我正在努力通过 WCF 服务保存 gridview。我已经尝试过并收到此错误:
“参数化查询 '(@Item1 narchar(4),@Item2 nvarchar(4000)) insert into ' 需要参数 '@item2',但未提供该参数。”
这是我的代码:
public string InsertProcesses(ProcessDetails proDetails)
{
string Message;
SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=WCFTest;Integrated Security=True;Pooling=False");
con.Open();
SqlCommand cmd = new SqlCommand("insert into SaveProcesses(Item1, Item2)values(@Item1, @Item2)", con);
cmd.Parameters.AddWithValue("@Item1", proDetails.Item1);
cmd.Parameters.AddWithValue("@Item2", proDetails.Item2);
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
Message = proDetails.Item1+ "Details accepted";
}
else
{
Message = proDetails.Item1+ "Details not accepted";
}
con.Close();
return Message;
}
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
ServiceReference6.ProcessDetails det2 = new ServiceReference6.ProcessDetails();
det2.Processes = dataGridView2.Rows[i].Cells["Item1"].Value.ToString();
det2.Processes = dataGridView2.Rows[i].Cells["Item2"].Value.ToString();
obj6.InsertProcesses(det2);
感谢您提供的任何帮助。请注意,这是我第一次尝试 WCF。
流程详细代码
[DataContract]
public class ProcessDetails
{
int id;
string item1;
string item2;
[DataMember]
public int Id
{
get
{
return id;
}
set
{
id = value;
}
}
[DataMember]
public string Item1
{
get
{
return item1;
}
set
{
item1 = value;
}
}
[DataMember]
public string Item2
{
get
{
return item2;
}
set
{
item2 = value;
}
}
}