我的 SQL 不应该转换为 Int O.o [英] My SQL Converting to Int when it shouldn't O.o

查看:27
本文介绍了我的 SQL 不应该转换为 Int O.o的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在从我的程序更新 SQL 记录时收到以下错误:

Okay, I'm receiving the following error whilst updating my SQL Record from my program:

System.Data.SqlClient.SqlException"类型的未处理异常发生在 System.Data.dll

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

附加信息:转换 nvarchar 时转换失败将完整成员"值设置为数据类型 int.

Additional information: Conversion failed when converting the nvarchar value 'Full Member' to data type int.

这是更新代码;(我已经标记了引用包含 TEXT 的文本框的两个点,但正试图无缘无故地转换为 INT.

Here's the Update code; (I've marked the two spots that refer to the textbox which contains TEXT, but is trying to be converted to INT for no reason.

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) 并且可以为 null.

My SQL Column 'Member_Status's datatype is varchar(35) and is nullable.

这里发生了什么;为什么要尝试将其转换为整数?

What's going on here; why's it trying to convert it to an integer?

{编辑 1}

我已经包含了表的列及其数据类型的屏幕截图 - SQL Management Studio 的屏幕截图.

I've included a screenshot of the table's columns and their datatypes - Screenshot from SQL Management Studio.

推荐答案

糟糕,这归结于我的其他代码,它使用所选索引的数据填充字段.原来正式成员"实际上不在正确的文本框中,因此被发送到 INT 列之一.调试器应该更明显一点:/感谢您的帮助!

Woops, this was down to my other code which populates the fields with the data of the selected index. Turns out the 'Full Member' wasn't actually in the right text box and thus was being sent to one of the INT column. The debugger should have been a little more obvious with that :/ Thanks for your help people!

这篇关于我的 SQL 不应该转换为 Int O.o的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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