I am having trouble inserting the integer value [Question Type] and the string [Question Space] into my database at the same time into the same row. Whenever I click the button and try to execute an error comes up saying:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Incorrect syntax near '('.
Code:
SqlCommand command5 = new SqlCommand("INSERT INTO ([Question Space], [Question Type]) Questions VALUES ('@QuestionText', '@checkedradiobutton')", connect);
command5.Parameters.AddWithValue("@QuestionText", QuestionText);
command5.Parameters.AddWithValue("@checkedradiobutton", checkedradiobutton);
command5.ExecuteNonQuery();
I would appreciate any help that anyone can give me.
Here's the whole code for the button if you want to see:
private void button1_Click(object sender, EventArgs e)
{
string connectionString = ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString;
SqlConnection connect = new SqlConnection(connectionString);
connect.Open();
int checkedradiobutton = 0;
if(radioButton1.Checked)
{
checkedradiobutton = 1;
}
else if(radioButton2.Checked)
{
checkedradiobutton = 2;
}
else if(radioButton3.Checked)
{
checkedradiobutton = 3;
}
string QuestionText = QuestionBox.Text;
SqlCommand command5 = new SqlCommand("INSERT INTO ([Question Space], [Question Type]) Questions VALUES ('@QuestionText', '@checkedradiobutton')", connect);
command5.Parameters.AddWithValue("@QuestionText", QuestionText);
command5.Parameters.AddWithValue("@checkedradiobutton", checkedradiobutton);
command5.ExecuteNonQuery();
}
And my database table:
CREATE TABLE [dbo].[Questions]
(
[QuestionID] INT IDENTITY (1, 1) NOT NULL,
[Actual answer] NVARCHAR (50) NULL,
[Question Space] NVARCHAR (50) NULL,
[Question Type] INT NULL,
PRIMARY KEY CLUSTERED ([QuestionID] ASC)
);