1

I have the following code snippet :-

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    string idd = Session["senderefirstname"].ToString();

    Query = " create table '"+ idd +"' (  senderid varchar(90) , recipientid     varchar(90),senderimage varchar(90), senderfirstname varchar(90), senderlastname varchar(90),    message varchar(max) ) ";
    adap = new SqlDataAdapter(Query, con);
    ds = new DataSet();
    adap.Fill(ds); 
    Response.Redirect("newmessage.aspx");
}

but m getting the error is

"Incorrect syntax near 'noah'"

noah is the string stored in session["senderfirstname"] I'm getting this error. Can anyone guide?

3 Answers 3

3

You don't need to use single quotes when you use CREATE TABLE.

Just use create table "+ idd +"

Take a look at syntax from CREATE TABLE (Transact-SQL)

But more important, I don't understand your code at all. I don't think you need to use SqlDataAdapter or DataSet because your query does not return anything.

Just execute your query with SqlCommand.ExecuteNonQuery method like;

Query = " create table "+ idd +"(senderid varchar(90), recipientid varchar(90),senderimage varchar(90), senderfirstname varchar(90), senderlastname varchar(90),message varchar(max)) ";
SqlCommand cmd = new SqlCommand(Query, con);
cmd.ExecuteNonQuery();
Sign up to request clarification or add additional context in comments.

Comments

0
Query = " create table "+ idd +" (  senderid varchar(90) , recipientid     varchar(90),senderimage varchar(90), senderfirstname varchar(90), senderlastname varchar(90),    message varchar(max) ) ";

I think that should work.

Comments

0

Try this..

Query= "create table "+ idd +"(senderid varchar(90),recipientid varchar(90),senderimage varchar(90), senderfirstname varchar(90), senderlastname varchar(90),message varchar(max) ) ";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.