可能重复:
INSERT 查询,它返回 1(插入 1 行)。但是当我查看表格时,我什么也没看到。下面代码中的return语句返回1
string connectionString = @"Data Source=|DataDirectory|\SAW - DB STORE.sdf",
result = "";
using (SqlCeConnection con = new SqlCeConnection(connectionString))
{
using (SqlCeCommand com = new SqlCeCommand())
{
com.CommandText = "INSERT INTO Words (Word, Word_Length, Bonus_Word, Points) VALUES (@wrd, @len, @bnus_wrd, @points)";
com.Parameters.AddWithValue("@wrd", wrd);
com.Parameters.AddWithValue("@len", len);
com.Parameters.AddWithValue("@bnus_wrd", bnus_wrd);
com.Parameters.AddWithValue("@points", points);
com.CommandType = System.Data.CommandType.Text;
com.Connection = con;
con.Open();
try
{
int r = com.ExecuteNonQuery();
result = string.Format("{0} WORD ADDED", r);
}
catch (Exception ex)
{
result = string.Format("Error found: {0}", ex.Message);
}
finally
{
con.Close();
}
}
}
label7.Visible = true;
label7.Text = result;
SqlCeConnection con1 = new SqlCeConnection(@"Data Source=|DataDirectory|\SAW - DB STORE.sdf");
con1.Open();
SqlCeCommand com1 = new SqlCeCommand();
com1.CommandText = "Select * From Words";
com1.CommandType = System.Data.CommandType.Text;
com1.Connection = con1;
SqlCeDataReader read;
read = com1.ExecuteReader();
while (read.Read())
{
MessageBox.Show("Text =" + read[1]);
}
con1.Close();
表只有我手动添加的数据而不是插入查询?使用 Visual Studio 2012 数据应该在表中,但如果通过插入查询添加则不是