Click here to Skip to main content
15,899,825 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Must declare the scalar variable "@DateCreated".
Ive got that error when i hit submit button. I just want to add new record in database. Sir what is the problem?
SQL
Dim strSQL As String
Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
strSQL = "INSERT INTO [TblDUMMY](UserID, CostCenter, Curriculum, College, Category, CourseCode, CourseTitle, Duration, Discipline, Date_Created) VALUES (@UserID, @CostCenter, @Curriculum, @College, @Category, @CourseCode, @CourseTitle, @Duration, @Discipline, @DateCreated)"
connection.Open()
Dim command As New SqlCommand(strSQL, connection)
command.Parameters.Add("@CostCenter", SqlDbType.NVarChar).Value = lbl15029.Text
command.Parameters.Add("@Discipline", SqlDbType.NVarChar).Value = txt15029.Text
command.Parameters.Add("@College", SqlDbType.NVarChar).Value = ddCollege.Text
command.Parameters.Add("@Curriculum", SqlDbType.NVarChar).Value = ddCurriculum.Text
command.Parameters.Add("@Category", SqlDbType.NVarChar).Value = lblGEE.Text
command.Parameters.Add("@CourseCode", SqlDbType.NVarChar).Value = txtCCode.Text
command.Parameters.Add("@CourseTitle", SqlDbType.NVarChar).Value = txtCT.Text
command.Parameters.Add("@Duration", SqlDbType.NVarChar).Value = txtDuration.Text
command.Parameters.Add("@UserID", SqlDbType.NVarChar).Value = lblposition2.Text
command.Parameters.AddWithValue(",@DateCreated", SqlDbType.NVarChar).Value = Label1.Text
command.ExecuteNonQuery()
connection.Close()
Posted

<pre lang="c#">com.Parameters.AddWithValue("@par",TextBox1.Text);</pre>
 
Share this answer
 
I am would suggest the comma pre-pended in the @DateCreated variable name
command.Parameters.AddWithValue(",@DateCreated", SqlDbType.NVarChar).Value = Label1.Text
 
Share this answer
 
remove the first comma from
command.Parameters.AddWithValue(",@DateCreated", SqlDbType.NVarChar).Value = Label1.Text
 
Share this answer
 
v2
Comments
Reiss 13-Jul-11 3:31am    
just beat me to it ;-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900