ذخیره یک فیلد از دیتا بیس در یک متغیر
من میخوام یک فیلد از جدولو که از نوع bigint هست ،رو توی یک متغیر از نوع int ذخیره کنم..نمیدونم کدش چطوریه....این هم چیزیه که من نوشتم....
dastor.CommandText = @" select id from seller where name='" + textBox7.Text + "' ";
SqlDataReader reader = dastor.ExecuteReader();
while (reader.Read())
int16 a=Convert.ToInt16 (reader[0]);
نقل قول: ذخیره یک فیلد از دیتا بیس در یک متغیر
به اینصورت :
int a=0;
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=University;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select *from Table_3",con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
a=Int32.Parse(dr["ID"].ToString());
}
con.Close();