hi i am working on school assignment which is due real soon. but i seem to have an error that ssays sytax error near '=' at line 39. here's my code. i hope someone would point out whats not right with it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Lab_11_2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            SqlConnection conn = new SqlConnection("Data Source=localhost;" + 
                "Initial Catalog=StudentInfo; Integrated Security= SSPI");
            SqlCommand cmdEng_Dip = new SqlCommand("SELECT * FROM whereEng_Dip = @Eng_Dip", conn);
            conn.Open();
            SqlDataReader dr;
            dr = cmdEng_Dip.ExecuteReader();
            ddCourseName.DataTextField = "Course_Name";
            ddCourseName.DataBind();

            dr.Close();
            conn.Close();
        }
    }
    protected void ddCourseName_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection("Data Source=localhost;" +
            "Initial Catalog=StudentInfo; Integrated Security= SSPI");
        string mySQL;
        mySQL = "SELECT * from Eng_Dip = @par_Course_Name";
        SqlCommand cmdDipInfo = new SqlCommand(mySQL, conn);
        cmdDipInfo.Parameters.AddWithValue("@par_Course_Name", ddCourseName.SelectedItem.Text);
        conn.Open();
        SqlDataReader dr;
        dr = cmdDipInfo.ExecuteReader();


        if (dr.Read())
        {
            txtCourseCode.Text = dr["Course_Code"].ToString();
            txtCourseDesc.Text = dr["Course_Desc"].ToString();
        }
        dr.Close();
        conn.Close();
    }
}

Edited 1 Year Ago by Nur_4

mySQL = "SELECT * from Eng_Dip = @par_Course_Name";

mySQL = "SELECT * from Eng_Dip WHERE Course_Name = @par_Course_Name";

Same on line 18. The syntax is

SELECT * FROM table WHERE column = 'value'

Edited 1 Year Ago by pritaeas

This article has been dead for over six months. Start a new discussion instead.