エラーを理解するのに助けが必要です。テーブルからデータを読み込みたいのですが、「行/列にデータがありません」などのエラーが出ます。実際には行と列があるので、わかりません。Winフォーム。ありがとう!
//this is how i insert data into table, works fine
public void b1_Click(object sender, EventArgs e)
{
SqlCeCommand command = new SqlCeCommand("INSERT INTO tbl1(Name, LastName) VALUES (@Name, @LastName)", conn);
command.Parameters.AddWithValue("@Name", l1.Text);
command.ExecuteNonQuery();
}
//this is how i try to read data from the same table
public void b2_Click(object sender, EventArgs e)
{
SqlCeConnection conn = new SqlCeConnection(@"Data Source=C:test.sdf");
conn.Open();
SqlCeCommand command = new SqlCeCommand("SELECT * FROM tbl1", conn);
SqlCeDataReader reader = command.ExecuteReader();
//error here
string Name = reader.GetString(0);
label.Text = Name;
}