好的,我从我的程序更新SQL记录时收到以下错误:
类型'System.Data.SqlClient.SqlException'的未处理异常 发生在System.Data.dll
中其他信息:转换nvarchar时转换失败 值'Full Member'到数据类型int。
这是更新代码; (我已经标记了两个引用包含TEXT的文本框的位置,但是试图无缘无故地转换为INT。
Public Class EditSelected
Dim con As SqlConnection
Dim stcon As String
Dim cmd As SqlCommand
Dim ds As DataSet
Dim da As SqlDataAdapter
Private Sub EditSelected_Load(sender As Object, e As EventArgs) Handles MyBase.Load
stcon = "{Censored Connection String}"
con = New SqlConnection(stcon)
con.Open()
cmd = New SqlCommand("UPDATE PersonsA SET Members_ID=@id, Gamer_Tag=@gt, " & _
"Screenname=@screen, First_Name=@first, Last_Name=@last, DoB=@dob," & _
"E_Mail_Address=@email, Position=@pos, U_G_Studio=@ustudio, Cautions=@caution," & _
"Record=@record, Event_Attendance=@event, Member_Status=@memstatus, " & _ '<---ERROR HERE
"GTA_V_Crew_Member=@gtva, Games_Owned=@gameowned, Rep_Group=@repgroup " & _
"WHERE Members_ID=@id", con)
cmd.Parameters.AddWithValue("@id", midtxt.Text)
cmd.Parameters.AddWithValue("@gt", gttxt.Text)
cmd.Parameters.AddWithValue("@screen", sntxt.Text)
cmd.Parameters.AddWithValue("@first", fntxt.Text)
cmd.Parameters.AddWithValue("@last", lntxt.Text)
cmd.Parameters.AddWithValue("@dob", dobtxt.Text)
cmd.Parameters.AddWithValue("@email", emailtxt.Text)
cmd.Parameters.AddWithValue("@pos", teamptxt.Text)
cmd.Parameters.AddWithValue("@ustudio", ugptxt.Text)
cmd.Parameters.AddWithValue("@caution", ugctxt.Text)
cmd.Parameters.AddWithValue("@record", recordtxt.Text)
cmd.Parameters.AddWithValue("@event", eventatxt.Text)
cmd.Parameters.AddWithValue("@memstatus", memberstatcombo.Text) '<---ERROR HERE
cmd.Parameters.AddWithValue("@gtva", gtavcrewmembercombo.Text)
cmd.Parameters.AddWithValue("@gameowned", gamesownedtxt.Text)
cmd.Parameters.AddWithValue("@repgroup", RepGroupcombo.Text)
cmd.ExecuteNonQuery()
MsgBox("Data has been saved!")
da = New SqlDataAdapter("SELECT * FROM PersonsA", con)
ds = New DataSet
da.Fill(ds, "PersonsA")
LeadersAccessTable.DataGridView1.DataMember = "PersonsA"
LeadersAccessTable.DataGridView1.DataSource = ds
con.Close()
我的SQL列'Member_Status的数据类型为varchar(35)
并且可以为空。
这里发生了什么;为什么要尝试将其转换为整数?
{编辑1}
我已经包含了表格列及其数据类型的屏幕截图 - 来自SQL Management Studio的屏幕截图。
答案 0 :(得分:0)
Woops,这取决于我的其他代码,它使用所选索引的数据填充字段。事实证明,“正式成员”实际上并不在正确的文本框中,因此被发送到INT列中的一个。调试器应该更加明显:/感谢您的帮助!