Im trying to update the content in the database but it doesnt work i dont understand why.
I commented most of the code tell me if something is unclear
Get content code:
//if creating new file use textbox1 rather then the double clicked data cell
string fns = "";
if (open == false)
{
dataGridView1.CurrentCell = this.dataGridView1[0, e.RowIndex];
fns = dataGridView1.CurrentCell.Value.ToString();
}
else
{
//use filename box (file creation)
fns = textBox1.Text;
}
// get content where name == fns
SqlConnection sql = new SqlConnection(sqlcon);
a = new SqlDataAdapter("SELECT [Content], [primkey], [Name] FROM Keeper WHERE [Name] ='" + fns + "'", sqlcon);
try
{
a.Fill(s, "Keeper");
foreach (DataRow dr in s.Tables[0].Rows)
{
dataGridView2.DataSource = s;
dataGridView2.DataMember = "Keeper";
}
//get content from datagrid insert into richtextbox
dataGridView2.CurrentCell = this.dataGridView2[0, 0];
richTextBox1.Text = dataGridView2.CurrentCell.Value.ToString();
}
catch (SqlException sqlexcp)
{
MessageBox.Show(sqlexcp.Message.ToString());
}
//close connection, reset bool, bring up editor
sql.Close();
open = false;
richTextBox1.BringToFront();
Save content:
//get content from textbox insert into datagrid
dataGridView2.CurrentCell = this.dataGridView2[0, 0];
dataGridView2.CurrentCell.Value = richTextBox1.Text;
//update DB
SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(a);
a.Update(s, "Keeper");