In my SQL database I have a table for every state in the USA. The user can create multiple pages in different states. Each table has a "UserID" column that will always match the logged in user. How do I search multiple tables for the "UserID"?
string sqlquery = "SELECT * FROM[all tables] WHERE @UserID ='" + userID.Text + "'";
SqlConnection conn1 = new SqlConnection(connString);
SqlCommand comm1 = new SqlCommand(sqlquery, conn1);
SqlDataReader DR1 = comm1.ExecuteReader();
if (DR1.Read())
{
Textbox1.Text = DR1.GetValue(0).ToString();
}
GetValue(0).ToString()call is what flavor of the database are you using..? is this SQLite? or Sql Server.., etc..? also you need to do your gathering and storage, into a List or other type of Collection.. I worked helping someone earlier using the GetValue() method and this yields errors just a heads up ..Select *when all you are looking for is the userId, also where are you creating thecomm1.Parameters.AddWithValues("@UserID", userId.Text)which by the way you should use a property and have proper validation otherwise you are setting yourself up for sql injection.The way the code / query stands I doubt that you will get the intended results