Busque los estudiantes desde el script de unión interno. "’sintaxis incorrecta cerca de la palabra clave ‘dónde’.’

programación

[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.  

Lo que he probado:

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+"'";

Solución 1

Como señala Dave, puede simplificar su consulta. Además, no pasas parámetros como ese.

Prueba esto:

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]

コメント

Título y URL copiados