所以我设法通过WCF将整个datagridview保存到我的数据库中,但现在我只想保存由CHeck框声明的选定行。有人可以帮忙吗?
这是我保存整个datagridview的代码片段,但现在我只需保存所选项目:
for ( int i = 0; i < dataGridView2.Rows.Count; i++)
{
ServiceReference6.ProcessDetails det2 = new ServiceReference6.ProcessDetails();
det2.Item1 = dataGridView2.Rows[i].Cells["Item1"].Value.ToString();
det2.Item2 = dataGridView2.Rows[i].Cells["Item2"].Value.ToString();
obj6.InsertProcesses(det2);
}
这是我的WCF代码:
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;
}
答案 0 :(得分:0)
for ( int i = 0; i < dataGridView2.Rows.Count; i++)
{
CheckBox chk = new CheckBox();
chk = (CheckBox)(dataGridView2.Rows[iCount].FindControl("checkbox1"));
if (chk.Checked)
{
"do your code here"
}
}
请根据您的要求更改控件名称。