PDA

View Full Version : مبتدی: ذخیره یک فیلد از دیتا بیس در یک متغیر



saman shabani
چهارشنبه 02 فروردین 1391, 23:47 عصر
من میخوام یک فیلد از جدولو که از نوع 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]);

Sirwan Afifi
پنج شنبه 03 فروردین 1391, 00:01 صبح
به اینصورت :

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();