Database (.Sdf) not getting updated when insert new row or delete new row. Kindly Help please.

Posted by Dnarayan under C# on 8/30/2015 | Points: 10 | Views : 476 | Status : [Member] | Replies : 2
Dear Friends
I am a newbie and developing a project for my BSc CS.
In VS 2010, using c# and local database .sdf file (SQLCE).
application runs fine but it DOES NOT GET UPDATED in SQL DATABASE. but displays the new record in data grid view below my code. Please help what i should change?
surprisingly no Errors r exceptions messages even after adding try - catch.

TO FILL DATA GRID VIEW FROM THE SDF FILE -- SVITMS.SDF
---------------------------------------------------------
void FillData()
{
using (SqlCeConnection c = new SqlCeConnection(@"Data Source=D:\Library_MGMT 3\Library_MGMT\SVITMS.sdf"))

{
c.Open();

// Create new DataAdapter

using (SqlCeDataAdapter a = new SqlCeDataAdapter("SELECT * FROM BooksTbl", c))
{

DataTable t = new DataTable();

a.Fill(t);

BooksdataGridView.DataSource = t;

}

c.Close();

}

INSERT COMMAND BUTTON CLICK EVENT - table name = BooksTbl
-------------------------------------
private void Insertbutton_Click(object sender, EventArgs e)
{

SqlCeConnection c = new SqlCeConnection(@"Data Source=D:\Library_MGMT 3\Library_MGMT\SVITMS.sdf");

c.Open();

SqlCeCommand cmd = c.CreateCommand();

cmd.CommandType = CommandType.Text;

cmd.CommandText = "Insert into BooksTbl values('" + ACCTextBox.Text + "','" + AuthorTextBox.Text + "'" )";
cmd.ExecuteNonQuery();

FillData();

}




Responses

Posted by: Shreedar on: 8/31/2015 [Member] Starter | Points: 25

Up
0
Down
Hi

Try by replacing the below lines in your code.

cmd.CommandText = "Insert into BooksTbl values
('" + ACCTextBox.Text + "','" + AuthorTextBox.Text
+ "' )";
cmd.ExecuteNonQuery();

Regards

Sridhar Thota.
www.dotnet-sridhar.blogspot.com

Dnarayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dnarayan on: 8/31/2015 [Member] Starter | Points: 25

Up
0
Down
I dint understand dear Shreedar, you answer looks the same as my code.
Kindly explain what I am missing please/.


Dnarayan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response