我需要一些帮助来理解我的错误。我想从表中读取数据,但是我收到诸如“行/列不存在数据”之类的错误。我不明白,因为我实际上在那里有行和列。赢表格。谢谢!
//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;
}