【发布时间】:2012-01-31 16:59:00
【问题描述】:
添加新数据时总是出错。错误说
字符串或二进制数据将被截断。声明已终止
我回顾了我的后端或代码。在一列中添加TWO LABEL DATA 似乎存在冲突,因为我想加入(年份)-(学生编号)
这是我的 INSERT INTO 语句的代码
INSERT INTO
[Student_Information] (StudentID, LastName, FirstName, MiddleName, Gender,
ContactNumber, Citizenship, Religion, Birthday, Address)
VALUES
( '" & lbl_cyear.Text - studid.Text & "','" + txt_lname.Text + "', '" + txt_fname.Text + "', '" + txt_mname.Text + "', '" + DDGender.Text + "', '" & txt_cnumber.Text & "', '" & txt_citizenship.Text & "' , '" + txt_religion.Text + "' , '" & txt_bday.Text & "', '" & txt_address.Text & "' )"
这是我如何生成年份和学号的代码
Sub SNYear()
Dim test As Date
test = Convert.ToDateTime(Today)
lbl_cyear.Text = test.Year
End Sub
Sub SNGenerate()
'displaying Studentid
Dim SN As Integer ' Student Number
Dim SID As String 'Student ID Num as String
Dim rdr As SqlDataReader
cmd1.Connection = cn
cmd1.Connection.Open()
cmd1.CommandText = "Select Max (StudentID) as expr1 from [Student_Information]"
rdr = cmd1.ExecuteReader
If rdr.HasRows = True Then
rdr.Read()
End If
If rdr.Item(0).ToString = Nothing Then
SN = rdr.Item(0) + 1
SID = Format(SN, "0000")
ElseIf rdr.Item(0).ToString = 0 Then
SN = rdr.Item(0) + 1
SID = Format(SN, "0000")
Else
SN = rdr.Item(0) + 1
SID = Format(SN, "0000")
End If
studid.Text = SID
cmd1.Connection.Close()
End Sub
有人可以帮我写代码吗?如何在不同的标签文本中连接 2 个数据并将其保存到我的表中的一列中。
【问题讨论】:
-
为你重新标记了这个问题。问题与 Visual Basic 和 SQL 有关——根本与 ASP.NET 无关。
-
您的意思是将
StudentID设置为lbl_cyear.Text - studid.Text?