Please help. This is for a UI I have worked on for about 6 weeks for my company's Client Services team that is itching to use it.
As in the title, I am trying to select an 'ID' value associated with a row that contains a checkbox. If that checkbox is 'checked' I want a select statement to run and grab the 'ID' value from that row.
protected void UpdateSelectedRecords()
{
string strPerSignStart = "%";
string strPerSignEnd = "%";
string strDbSearch = strPerSignStart + ddlDatabasesUpdateTCID.Text + strPerSignEnd;
object NewTCID = txtTargetCID.Text;
DateTime curtstmp = DateTime.Now;
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
chkBox = (row.Cells[0].Controls[0] as CheckBox);
if (chkBox != null && Convert.ToBoolean(chkBox.Checked) == true)
{
OdbcConnection Postgreconnect2 = new OdbcConnection("Driver= {PostgreSQL Unicode};Server=localhost;Port=5433;Database=postgres;Uid=xxx;Pwd=xxx");
Postgreconnect2.Open();
OdbcCommand cmd = new OdbcCommand("SELECT id FROM conceptidmapping WHERE database ILIKE " + "?" + " AND " + (chkBox.Checked == true) + " ORDER BY id ASC", Postgreconnect2);
cmd.Parameters.AddWithValue("@database", strDbSearch);
cmd.Parameters["@database"].Value = Convert.ToString(strDbSearch);
cmd.Connection = Postgreconnect2;
string idVal = (string)cmd.ExecuteScalar();
OdbcCommand cmd1 = new OdbcCommand("UPDATE conceptidmapping SET selected = true WHERE database ILIKE " + "?" + " AND id = " + idVal, Postgreconnect2);
cmd1.Parameters.AddWithValue("@database", strDbSearch);
cmd1.Parameters["@database"].Value = Convert.ToString(strDbSearch);
cmd1.Connection = Postgreconnect2;
cmd1.ExecuteNonQuery();
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire