You are missing the single quotes in your select command which is what is making your original SELECT
fail. However I would like to note that you should always parameterize and encapsulate your SqlCommand
/ SqlConnection
in a using
statement. The following would be a cleaner more secure way to solve your problem.
string s2 = "Select * from idtyfile where oysterid=@id";
DataTable myDataTable = new DataTable();
using (SqlConnection conn = new SqlConnection(myConnectionString))
using (SqlCommand cmd = new SqlCommand(s2, conn))
{
cmd.Parameters.AddWithValue("@id", id);
conn.Open();
myDataTable.Load(cmd.ExecuteReader());
}
For some educational resources, you should look at the following links.
MSDN Reference for the using
keyword
MSDN Reference for SqlCommand
-- Look at the Parameters
property.