Tìm kiếm các học sinh từ tập lệnh tham gia bên trong "’cú pháp sai gần từ khóa ‘ở đâu’.’

lập trình

[ad_1]

private void button1_Click(object sender, EventArgs e)
        {
            con.Open();
            string str = "select * from (select tblNewAdmission.NAID as student_ID,tblNewAdmission.fname as full_name,tblNewAdmission.mname as Monther_Name,tblNewAdmission.gender as Gender,tblNewAdmission.dob as Date_of_Birth,tblNewAdmission.mobile as Mobile,tblNewAdmission.email as Email_ID,tblNewAdmission.semester,tblNewAdmission.prog as Programing_Language,tblNewAdmission.sname as school_name,tblNewAdmission.duration as Course_duration,tblNewAdmission.addres as Address,tblfee.fee as Fees from tblNewAdmission inner join tblfee on tblNewAdmission.NAID=tblfee.NAID) where NAID = '"+textBox1.Text+"'";
            SqlCommand cmd = new SqlCommand(str, con);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
            //cmd.ExecuteNonQuery();
            con.Close();
        }
above code Iam writing in the button click event for searching students


Iam using the joins to get the result from the 2 tables but when iam searching specfic student from the above script inner join result, iam not geeting 
can you please help me with script.  

Những gì tôi đã thử:

string str = "select * from (select tblNewAdmission.NAID as student_ID,tblNewAdmission.fname as full_name,tblNewAdmission.mname as Monther_Name,tblNewAdmission.gender as Gender,tblNewAdmission.dob as Date_of_Birth,tblNewAdmission.mobile as Mobile,tblNewAdmission.email as Email_ID,tblNewAdmission.semester,tblNewAdmission.prog as Programing_Language,tblNewAdmission.sname as school_name,tblNewAdmission.duration as Course_duration,tblNewAdmission.addres as Address,tblfee.fee as Fees from tblNewAdmission inner join tblfee on tblNewAdmission.NAID=tblfee.NAID) where NAID = '"+textBox1.Text+"'";

Giải pháp 1

Như Dave đã chỉ ra, bạn có thể đơn giản hóa truy vấn của mình. Ngoài ra, bạn không truyền tham số như thế.

Thử cái này xem sao:

C#
string str = "SELECT tblNewAdmission.NAID AS student_ID, tblNewAdmission.fname AS full_name, tblNewAdmission.mname AS Monther_Name, tblNewAdmission.gender AS Gender, tblNewAdmission.dob AS Date_of_Birth, tblNewAdmission.mobile AS Mobile, tblNewAdmission.email AS Email_ID, tblNewAdmission.semester, tblNewAdmission.prog AS Programing_Language, tblNewAdmission.sname AS school_name, tblNewAdmission.duration AS Course_duration, tblNewAdmission.addres AS Address, tblfee.fee AS Fees FROM tblNewAdmission INNER JOIN tblfee ON tblNewAdmission.NAID = tblfee.NAID WHERE tblNewAdmission.NAID = @NAID";

using (SqlCommand command = new SqlCommand(str, con))
{
    command.Parameters.AddWithValue("@NAID", textBox1.Text);

    // Execute your query and process the result
}

[ad_2]

コメント

タイトルとURLをコピーしました