I'm making a simple web app like Instagram. I want to store images for each user in separate table, for example:
- New users login is Bob123,
- Create a new record in table Users (Uzytkownicy) for Bob123,
- Create a new table, in the same database, called Bob123 and there store all Bobs images
I'm getting an error: Incorrect syntax near '@name'
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
try
{
if (temp == 0)
{
Guid newGuid = Guid.NewGuid();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["UzytkownicyConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into Uzytkownicy (Id, Login, Password) values (@id, @Uname, @password)";
SqlCommand com = new SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue("@id", newGuid.ToString());
com.Parameters.AddWithValue("@Uname", TextBoxUN.Text);
com.Parameters.AddWithValue("@password", TextBoxPass.Text);
SqlCommand comm = new SqlCommand("CREATE TABLE @name ([Image] VARBINARY (MAX) NOT NULL);", conn);
comm.Parameters.AddWithValue("@name", TextBoxUN.Text);
com.ExecuteNonQuery();
comm.ExecuteNonQuery();
Response.Redirect("MainWebSite.aspx");
conn.Close();
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.ToString());
}
}