erdcannet' Alıntı:
İsteğiniz tam olarak 4 parametreyi kullanarak tek bir öğrenciyi getirmek midir hocam?
Evet ama herhangi birini de girsem arama yapacak 2 sini girsem o iki kriter için arayacak 3ünü girsem o girilen 3 ü için arayacak
Bilmem anlatabildim mi.
Daha detaylı anlatayım.
Öğrenci bilgilerini adına göre, adı ve soyadına göre,tc sine göre sınıfına göre aratmak istiyorum.
Örnek sınıfa göre 11.sınıflar hepsi gelecek Bir de şubeyi A seçersem 11 A dakiler gelsin.
Veya Adı ahmet olanlar listelensin aynı zaman da soyadına göre soyadı sayın olanlar gelsin gibi...
Birden fazla kritere göre arama ve tek sql kodunda yazmak istiyorum.
Ben iç içe iflerle yapmaya çalışıyorum ama aşağıdaki gibi...
Sql de sorgulanın içeriğini görmüyor maalesef.
if (TextBox2.Text != "")
{
if (sorgula == "")
{
sorgula = "tc='" + TextBox2.Text + "'";
}
else
{
sorgula = "tc='" + TextBox4.Text + "' + " + sorgula + "";
}
}
if (TextBox3.Text != "")
{
if (sorgula == "")
{
sorgula = "adi like '" + TextBox3.Text + "'";
}
else
{
sorgula = "adi like '" + TextBox3.Text + "' + " + sorgula + "";
}
}
if (TextBox4.Text != "")
{
if (sorgula == "")
{
sorgula = "sadi='" + TextBox4.Text + "'";
}
else
{
sorgula = "sadi='" + TextBox4.Text + "' + " + sorgula + "";
}
}
if (TextBox3.Text != "")
{
if (sorgula == "")
{
sorgula = "okulno='" + TextBox3.Text + "'";
}
else
{
sorgula = "okulno='" + TextBox3.Text + "' + " + sorgula + "";
}
}
if (DropDownList1.Text != "")
{
if (sorgula == "")
{
sorgula = "sinif='" + DropDownList1.Text + "'";
}
else
{
sorgula = "sinif='" + DropDownList1.Text + "' + " + sorgula + "";
}
}
if (DropDownList2.Text != "")
{
if (sorgula == "")
{
sorgula = "sube='" + DropDownList2.Text + "'";
}
else
{
sorgula = "sube='" + DropDownList2.Text + "' + " + sorgula + "";
}
}
if (sorgula != "")
{
OleDbConnection baglan1 = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; DATA Source=" + Server.MapPath("App_Data/bilgilerim.accdb"));
OleDbCommand sg = new OleDbCommand("Select tc,adi,sadi,okulno,sinif,sube from ogrenciler where sorgula", baglan1);
OleDbDataAdapter adp = new OleDbDataAdapter(sg);
DataTable dt = new DataTable();
baglan1.Open();
adp.Fill(dt);
if (dt != null && dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
DropDownList1.Text = "";
DropDownList2.Text = "";
GridView1.HeaderRow.Cells[1].Text = "T.C Kimlik No";
GridView1.HeaderRow.Cells[2].Text = "Ad";
GridView1.HeaderRow.Cells[3].Text = "Soyad";
GridView1.HeaderRow.Cells[4].Text = "Okul No";
GridView1.HeaderRow.Cells[5].Text = "Sinif";
GridView1.HeaderRow.Cells[6].Text = "Subesi";
GridView1.Visible = true;
}