必须声明标量变量“@ DateCreated”。 [英] Must declare the scalar variable "@DateCreated".

查看:107
本文介绍了必须声明标量变量“@ DateCreated”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必须声明标量变量@DateCreated。

当我按下提交按钮时出现错误。我只想在数据库中添加新记录。先生是什么问题?

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?

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()

推荐答案

我建​​议在@DateCreated变量名中预先填写逗号

command.Parameters.AddWithValue(,@ DateCreated,SqlDbType.NVarChar).Value = Label1.Text
I am would suggest the comma pre-pended in the @DateCreated variable name
command.Parameters.AddWithValue(",@DateCreated", SqlDbType.NVarChar).Value = Label1.Text


删除第一个逗号

command.Parameters.AddWithValue( @DateCreated,SqlDbType.NVarChar).Value = Label1.Text
remove the first comma from
command.Parameters.AddWithValue(",@DateCreated", SqlDbType.NVarChar).Value = Label1.Text


< pre lang =c#> com.Parameters.AddWithValue(@ par,TextBox1.Text);< / pre>
<pre lang="c#">com.Parameters.AddWithValue("@par",TextBox1.Text);</pre>


这篇关于必须声明标量变量“@ DateCreated”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆