اطلاعیه

Collapse
No announcement yet.

جست و جو در بانک اطلاعاتی در c#

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    جست و جو در بانک اطلاعاتی در c#

    من یه کومبوباکس و یه تکست باکس و یه دیتاگریدویو و یه دکمه گذاشتم.کههرکدوم کارای زیر رو انجام میدن:
    کومبوباکس رو واسه مشخص کردن نوع جست و جو گذاشتم.مثلا براساس نام یا فامیل یا شماره دانشجویی
    تکس باکس رو واسه نوشتن نام یا فامیل یا شماره دانشجویی طرف که می خام توی بانک جست و جوش کنم گذاشتم.
    دیتا گرید ویو رو واسه نمایش جست و جو
    دکمه رو هم کد های زیر براش نوشتم ولی جواب نمیده. هیچ گونه اروری نداره. ولی هیچ کاری هم نمیکنه.اگه میشه بگید مشکل از کجاس؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟ :sad:
    متغیر s1 رو سراسری تعریف کردم.
    DataSet ds = new DataSet();

    s = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|datadirecto ry|\\Database1.mdf;Integrated Security=True;User Instance=True";
    SqlConnection con = new SqlConnection(s);
    con.Open();
    if(comboBox1.Text=="رشته&quot
    {
    s1="select * from faregh where reshte = '" + textBox1.Text + "'";
    }
    else if(comboBox1.Text=="نام&quot
    {
    s1="select * from faregh where nam = '" + textBox1.Text + "'";
    }
    else if(comboBox1.Text=="شماره پرونده&quot
    {
    s1 = "select * from faregh where shomare_parvande = '" + textBox1.Text + "'";
    }
    else if(comboBox1.Text=="شماره دانشجویی&quot
    {
    s1 = "select * from faregh where shomsre_daneshjoo = '" + textBox1.Text + "'";
    }

    else if (comboBox1.Text == "نام خانوادگی&quot
    {
    s1 = "select * from faregh where family = '" + textBox1.Text + "'";
    }
    SqlDataAdapter da = new SqlDataAdapter(s1,con);
    da.Fill(ds,"faregh"
    dataGridView1.DataSource = ds;

    #2
    پاسخ : جست و جو در بانک اطلاعاتی در c#

    حله فهمیدم مشکل از کجاس.کد درست اینه:
    string s, s1;
    private void glassButton1_Click(object sender, EventArgs e)
    {


    s = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|datadirecto ry|\\Database1.mdf;Integrated Security=True;User Instance=True";
    SqlConnection con = new SqlConnection(s);
    con.Open();
    if(comboBox1.Text=="رشته&quot
    {
    s1="select * from faregh where reshte = '" + textBox1.Text + "'";
    }
    else if(comboBox1.Text=="نام&quot
    {
    s1="select * from faregh where nam = '" + textBox1.Text + "'";
    }
    else if(comboBox1.Text=="شماره پرونده&quot
    {
    s1 = "select * from faregh where shomare_parvande = '" + textBox1.Text + "'";
    }
    else if(comboBox1.Text=="شماره دانشجویی&quot
    {
    s1 = "select * from faregh where shomsre_daneshjoo = '" + textBox1.Text + "'";
    }
    else if (comboBox1.Text == "مقطع&quot
    {
    s1 = "select * from faregh where maghta = '" + textBox1.Text + "'";
    }
    else if (comboBox1.Text == "نام خانوادگی&quot
    {
    s1 = "select * from faregh where family = '" + textBox1.Text + "'";
    }

    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = s1;
    cmd.Connection = con;
    dataGridView1.DataSource = null;
    dataGridView1.Rows.Clear();
    dataGridView1.Refresh();
    SqlDataReader dr = cmd.ExecuteReader();
    object[] o1 = new object[8];
    while (dr.Read())
    {
    dr.GetValues(o1);
    dataGridView1.Rows.Add(o1);

    }

    }

    دیدگاه

    لطفا صبر کنید...