Hi,
I have a data grid and update this with sql command:
string str = @"update dbo." + tblname + "";
str += " set SettingValue = " + value + "";
str += " where id = '" + id + "'";
SqlCommand cm = new SqlCommand(str, MyConnection);
MyConnection.Open();
SqlDataReader re;
re = cm.ExecuteReader();
re.Close();
MyConnection.Close();
BindGrid();
and give data from datagridview for 'tblname' , 'id' and 'value':
int Id =Convert.ToInt32(dataGridView1.CurrentRow.Cells["id"].Value);
string tblname = dataGridView1.CurrentRow.Cells["TableName"].Value.ToString();
string val = textBox1.Text;
MyUpdate(tbl, val, Id);
and this is query for Bind Datagridview:
private void BindGrid()
{
dataGridView1.DataSource = bindingSource1;
var str = @"SELECT B.Id, CASE WHEN b.settingdesc IS NULL THEN b.settingkey WHEN b.settingdesc = '' THEN b.SettingKey WHEN b.settingdesc <> '' THEN b.settingDesc END AS settingdesc,
'SysSettingsDep' AS TableName, B.SettingValue AS settingvalue
FROM SysCustomer AS A INNER JOIN
SysSettingsDep AS B ON A.SettingKey = B.SettingKey
UNION
SELECT C.Id, CASE WHEN c.settingdesc IS NULL THEN c.SettingKey WHEN c.settingdesc = '' THEN c.SettingKey WHEN c.settingdesc <> '' THEN c.settingDesc END AS settingdesc,
'SysSettingsMachine' AS TableName, C.SettingValue AS settingvalue
FROM SysCustomer AS A INNER JOIN
SysSettingsMachine AS C ON A.SettingKey = C.SettingKey
UNION
SELECT D.Id , CASE WHEN d .settingdesc IS NULL THEN d .SettingKey WHEN d .settingdesc = '' THEN d .SettingKey WHEN d .settingdesc <> '' THEN d .settingDesc END AS settingdesc,
'SysSettings' AS TableName, D.SettingValue AS settingvalue
FROM SysCustomer AS A INNER JOIN
SysSettings AS D ON A.SettingKey = d.SettingKey";
SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCommand, MyConnection);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table; dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
}
The problem here is that when I enter the number to be updated, but the characters do not update.
why?
help me