public void doldur()
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Odev.mdf;Integrated Security=True");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * From ogrenciler Order By adsoyad ASC", con);
DataSet dts = new DataSet();
da.Fill(dts, "ogrenciler");
comboBox1.DataSource = dts.Tables["ogrenciler"];
comboBox1.ValueMember = "adsoyad";
comboBox1.DisplayMember = "adsoyad";
comboBox2.DataSource = dts.Tables["ogrenciler"];
comboBox2.ValueMember = "adsoyad";
comboBox2.DisplayMember = "adsoyad";
con.Close();
}
-combobox2 gets the data correctly-
private void ogrenci_Load(object sender, EventArgs e)
{
doldur();
}
-it is working either-
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Odev.mdf;Integrated Security=True");
con.Open();
SqlDataAdapter du = new SqlDataAdapter("Select * From ogrenciler Where adsoyad='"+ comboBox2.SelectedValue.ToString() +"'", con);
DataSet dy = new DataSet();
du.Fill(dy, "ogrenciler");
textBox7.Text = dy.Tables[0].Rows[0]["adsoyad"].ToString();
textBox8.Text = dy.Tables[0].Rows[0]["mail"].ToString();
textBox9.Text = dy.Tables[0].Rows[0]["sinif"].ToString();
textBox10.Text = dy.Tables[0].Rows[0]["sube"].ToString();
con.Close();
}
In here im getting:
"An exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll but was not handled in user code"(On textbox7 row)
I checked my table to be sure if I wrote correct SQL statement.(Everything is correct) Then I realize my dataadapter or dataset getting literally no data. Thats why I can't fill my textboxes. I tried to use datatable/rows.count, executescalar, datareader/dr.read, executereader. None of these worked. Then I started to suspect about my SQL Statement. Don't know how to fix. New to this language. I'm done. Please help me with this.
ps: This code was running properly 2days ago.
Edit 1: I just found out that If my combobox2's value includes "ı,ş,ğ" letters (and my first value includes "ş") i got this error.