这是我的代码,我想把它放到一个来自sql数据库的listview中,它只读取一个并在listview中只放一个项目,但是我想将数据库中的所有项目放到listview中。我的数据库有8个属性,但此代码仅显示第二个属性
alinanYemek.GridLines = true;
try
{
ListViewItem lvi = new ListViewItem();
if (connection.State == ConnectionState.Closed)
connection.Open();
SqlCommand cmd = new SqlCommand(
@"select * from YEMEK where PersonelKartID=@pID and OgrenciKartID = @oID", connection);
if (radio_ID == 'P')
{
cmd.Parameters.AddWithValue("@pID", _kimlik);
cmd.Parameters.AddWithValue("@oID", 0);
}
else
{
cmd.Parameters.AddWithValue("@pID", 0);
cmd.Parameters.AddWithValue("@oID", _kimlik);
}
var a = cmd.ExecuteScalar().ToString();
lvi.SubItems.Add(a);
alinanYemek.Items.Add(lvi);
connection.Close();
}
catch(Exception)
{
if(_dil == 'T')
MessageBox.Show("Girdiginiz kisi icin yemek bulmamaktadir");
else
MessageBox.Show("There is no meal selected for this person");
}
答案 0 :(得分:0)