مدیریت در نوشتن query در سی شارپ
سلام.
من کد زیر رو تو سی شارپ نوشتم. جواب هم میده. ولی اگر داده های ورودی رو اشتباه وارد کنیم، پیام خطای زیر رو میده.
چکار کنیم که اگه داده اشتباه بود، error نده و بجاش به کاربر اعلام کنه که باید داده رو درست وارد کنه؟
ممنون.
کد:
frm_main a = newfrm_main();
SqlConnection connect = newSqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + "\\Database1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand cmd1 = newSqlCommand("select name,id from forooshande where username='" + textBox1.Text + "' and password='" + textBox2.Text + "'", connect);
cmd1.Connection.Open();
SqlDataAdapter adp = newSqlDataAdapter();
adp.SelectCommand = cmd1;
DataTable dt = newDataTable();
adp.Fill(dt);
cmd1.Connection.Dispose();
a.label2.Text = dt.Rows[0][0].ToString();
a.txt_id.Text = dt.Rows[0][1].ToString();
a.Show();
this.Hide();
پیغام خطا:
کد:
There is no row at position 0.
:13::13::13::13::13::13::13::13::13::13::13::13::1 3: