PDA

View Full Version : SqlDataReader.GetValues



Mojgan110
پنج شنبه 23 آذر 1385, 00:37 صبح
سلام

میشه یه نمونه کد از SqlDataReader.GetValues بنویسید ؟

من اینجوری نوشتم ولی غلط گرفت : Invalid attempt to read when no data is present.


object[] valuez= new Object[2];
using (SqlConnection theCon = new SqlConnection(conStr))
{
SqlCommand cmd = new SqlCommand("Select * FROM Demo", theCon);
theCon.Open();
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
reader.GetValues(valuez);
MessageBox.Show(valuez[0].ToString());
reader.Close();
}

amirhkh
چهارشنبه 29 آذر 1385, 15:20 عصر
قبل از
reader.GetValues(valuez);

این کد رو اضافه کن
reader.Read()