System.Data.SqlClient.SqlException: Incorrect syntax near '='.
protected void btnLocate_Click(object sender, EventArgs e) { SqlConnection conDatabase = null; try { conDatabase = new SqlConnection("server=.;Initial Catalog=harika;Integrated Security=True"); conDatabase.Open(); SqlCommand command = new SqlCommand("SELECT * FROM dbo.cars" + "WHERE TagNumber = @TagNbr;", conDatabase); command.Parameters.Add("@TagNbr", SqlDbType.VarChar); command.Parameters["@TagNbr"].Value = txttag.Text; DataSet dsCars = new DataSet("CarsSet"); SqlDataAdapter sdaCars = new SqlDataAdapter(); sdaCars.SelectCommand = command; //command.CommandText = sdaCars.SelectCommand; sdaCars.Fill(dsCars); try { DataRow recCar = dsCars.Tables[0].Rows[0]; if (recCar.IsNull("CarID")) throw new IndexOutOfRangeException("Invalid Tag Number"); txtmake.Text = (string)recCar["Make"]; txtmodel.Text = (string)recCar["Model"]; txtyear.Text = (string)recCar["CarYear"]; chkk7.Checked = (bool)recCar["HasK7Player"]; chkcd.Checked = (bool)recCar["HasCDPlayer"]; chkdvd.Checked = (bool)recCar["HasDVDPlayer"]; chkavail.Checked = (bool)recCar["Available"]; } catch (IndexOutOfRangeException) { txttag.Text = ""; txtmake.Text = ""; txtmodel.Text = ""; txtyear.Text = ""; chkk7.Checked = false; chkcd.Checked = false; chkdvd.Checked = false; chkavail.Checked = false; } } finally { conDatabase.Close(); } } public SqlCommand Command { get; set; } } }
SqlCommand command = new SqlCommand("SELECT * FROM dbo.cars " + "WHERE TagNumber = @TagNbr", conDatabase);
SELECT * FROM dbo.cars" + "WHERE TagNumber = @TagNbr;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)