I have an error I don't understand how to get rid of. I want to compare a string consisting of: ID + " " + date + " " + time + ":00" to a string in the database (data type = text).
Here's an example of what I fetch from my gridview:
1 + " " + 2010-07-07 + " " + 10:00 + ":00" (i.e. 1 2010-07-07 10:00:00)
and this is what I want to compare it to:
1 2010-07-07 10:00:00
The error message says "Incorrect syntax near '2010'." What did I miss? The values I get when I try to debug are the exakt same values that I want to compare.
Here's the code (some of it in swedish *sorry*, some c# as well as sql:
int möteID; //=ID
string datum; //=date
string tid;
string starttid; //=the time I'm using
string sluttid;
string tillfälleID; //=the string from the gridview
StringBuilder str = new StringBuilder();
int index = int.Parse(e.CommandArgument.ToString());
möteID = Convert.ToInt32(GridViewFöreslagnaMöten.Rows[index].Cells[0].Text);
datum = Convert.ToString(GridViewFöreslagnaMöten.Rows[index].Cells[2].Text);
tid = Convert.ToString(GridViewFöreslagnaMöten.Rows[index].Cells[3].Text);
starttid = tid.Substring(1, 5);
sluttid = tid.Substring(9, 5);
tillfälleID = Convert.ToString(möteID + " " + datum + " " + starttid + ":00");
SqlConnection conn = new SqlConnection(config);
conn.Open();
string sql = "SELECT medlemID FROM MedlemTillfalle WHERE MedlemTillfalle.tillfalleID = " + tillfälleID;
SqlCommand comm = new SqlCommand(sql, conn);
SqlDataReader dr = comm.ExecuteReader(); //Incorrect syntax near '2010'
...and I'm aware I'm not using parameters... I'll be getting there soon, still a newbie.