0

所以我设法通过 WCF 将整个 datagridview 保存到我的数据库中,但现在我只想保存由复选框声明的选定行。任何人都可以帮忙吗?

这是我保存整个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;
    }
4

1 回答 1

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"
        }
      }

请根据您的要求更改控件的名称。

于 2013-06-17T10:42:25.137 回答