System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'id'. at System.Data.SqlClient.SqlConnection.OnError
Code :
try
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\SVB_db.mdf;Integrated Security=True");
con.Open();
SqlCommand cmd = null;
string sq = "SELECT event_name, user-id, time_in, time_out, event_date, venue_name FROM Event";
cmd = new SqlCommand(sq, con);
SqlDataReader r1 = cmd.ExecuteReader();
if (r1.HasRows)
{
while (r1.Read())
{
if (r1.GetValue(0).ToString().Equals(DropDownList1.SelectedItem.Value))
{
txtEventName.Text = r1.GetValue(0).ToString();
txtUsrID.Text = r1.GetValue(1).ToString();
txtTmeIn.Text = r1.GetValue(2).ToString();
txtTimeOut.Text = r1.GetValue(3).ToString();
txtEventDate.Text = r1.GetValue(4).ToString();
DropDownList1.Text = r1.GetValue(5).ToString();
}
}
r1.Close();
}
con.Close();
}
catch (Exception ex)
{
Response.Write(ex);
}
user-id is looking kinda suspicious. Maybe it should be
..., user_id, time_in...
If user-id is correct, than you should try
...[user-id], time_in ...
User contributions licensed under CC BY-SA 3.0