Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
string dbfile = "|DataDirectory|\\Database1.sdf";

string insertStmt = "select * from item";
string a = "insert into item(item1,item2) values('3','3')";


SqlCeCommand query,query1;
SqlCeConnection connection;
private void button1_Click(object sender, EventArgs e)
{
connection = new SqlCeConnection("Data Source=" + dbfile);
query = new SqlCeCommand(insertStmt, connection);

{


connection.Open();
query1 = new SqlCeCommand(a, connection);
query1.ExecuteNonQuery();
SqlCeDataReader r = query.ExecuteReader();
while (r.Read())
{
string cjdnc = r[0].ToString();
string kdmckd = r[1].ToString();
}

connection.Close();
}
}


in this code select query works fine
but insert query not inserting data in table item
nd also not showing any error
Posted
Comments
Sergey Vaselenko 4-Dec-13 5:13am    
Is this code working if you specify the database using a regular path instead of |DataDirectory|?

1 solution

Hello,

set your database property from Copy to Output directory to Copy Always.

Try this link

thanks
 
Share this answer
 
Comments
Abhijeet pratap singh 4-Dec-13 3:18am    
changed but still no data inserted in local data
Animesh Datta 4-Dec-13 3:42am    
have you modified the location of your database to PROJECTFOLDER\BIN\DEBUG ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900