重複の可能性:
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 のデータを使用するとテーブルにあるはずですが、挿入クエリを介して追加された場合はそうではありません