Hi..
currently im writing a database software using sqlite and this problem occurred.
http://i60.tinypic.com/1555hs9.png[
^]
at the beginning, the datatable was empty and I typed "Foo" as the name and "Bar" as the Item and when I load the datatable again into the data grid view it contains another "Foo" person without the value I entered into the Item column.
Here's the codes..
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int row = e.RowIndex;
DataGridViewCell IDcell = dataGridView1["ID", row];
bool newRow = false;
if (IDcell.Value.ToString().Length == 0)
newRow = true;
else
newRow = false;
if (con.State != ConnectionState.Open)
con.Open();
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = con;
if (newRow)
{
string sql = @" insert into myTable(Name, Item)
values(@name, @item)";
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("@name", dataGridView1["Name", row].Value.ToString());
cmd.Parameters.AddWithValue("@item", dataGridView1["Item", row].Value.ToString());
}
else
{
string sql = @" update myTable
set
Name = @name,
Item = @item
where ID = @id";
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("@name", dataGridView1["Name", row].Value.ToString());
cmd.Parameters.AddWithValue("@item", dataGridView1["Item", row].Value.ToString());
cmd.Parameters.Add("@id", DbType.Int32).Value = int.Parse(dataGridView1["ID", row].Value.ToString());
}
cmd.ExecuteNonQuery();
con.Close();
}
what's the wrong with my code ?
I dont want some meaningless Foo without the Bar.
Thanks in advance !