影响 sql 查询到文本框的结果
affect the result of sql query to textbox
我正在使用 sqlserver 2008 和 vb.net
我试图影响 sql 对我的文本框的查询结果。
这是我试过的代码
Dim rd As SqlDataReader
Try
Cn.Open()
cmd = New SqlCommand("SELECT pk_veh, désignation, projet, version, [taille de lot] from [Cutting software].dbo.vehicule WHERE désignation = '" & Form1.ComboBox3.SelectedValue & "'", Cn)
rd = cmd.ExecuteReader
While rd.Read
imp.TextBox1.Text = rd.GetInt32("pk_veh")
imp.TextBox2.Text = rd.GetString("désignation")
imp.TextBox3.Text = rd.GetString("projet")
imp.TextBox4.Text = rd.GetString("version")
imp.TextBox5.Text = rd.GetInt32("[taille de lot]")
imp.Show()
End While
Cn.Close()
Catch ex As SqlException
MessageBox.Show(ex.Message)
End Try
End Sub
当我检查我的专栏类型时,我总是遇到这个错误
System.InvalidCastException: 'La conversion de la chaîne "pk_veh" en type 'Integer' n'est pas valide.'FormatException: Input string was not in a correct format.
这里是我的专栏类型
pk_veh,[taille de lot] : int
名称、项目、版本:varchar[50]
这里是解决方案
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim rd As SqlDataReader
Try
Cn.Open()
Dim cmd As New SqlCommand("SELECT isnull(pk_veh,0)pk_veh, isnull(designation,'')designation, isnull(projet,'')projet, isnull(version,'')version, isnull(taille_de_lot,0)taille_de_lot from [Cutting software].dbo.vehicule WHERE designation = '" & Form1.ComboBox3.SelectedValue & "'", Cn)
rd = cmd.ExecuteReader
While rd.Read
imp.TextBox1.Text = rd.GetInt32(0)
imp.TextBox2.Text = rd.GetString(1)
imp.TextBox3.Text = rd.GetString(2)
imp.TextBox4.Text = rd.GetString(3)
imp.TextBox5.Text = rd.GetInt32(4)
End While
Cn.Close()
Catch ex As SqlException
MessageBox.Show(ex.Message)
End Try
imp.Show()
End Sub
我正在使用 sqlserver 2008 和 vb.net 我试图影响 sql 对我的文本框的查询结果。 这是我试过的代码
Dim rd As SqlDataReader
Try
Cn.Open()
cmd = New SqlCommand("SELECT pk_veh, désignation, projet, version, [taille de lot] from [Cutting software].dbo.vehicule WHERE désignation = '" & Form1.ComboBox3.SelectedValue & "'", Cn)
rd = cmd.ExecuteReader
While rd.Read
imp.TextBox1.Text = rd.GetInt32("pk_veh")
imp.TextBox2.Text = rd.GetString("désignation")
imp.TextBox3.Text = rd.GetString("projet")
imp.TextBox4.Text = rd.GetString("version")
imp.TextBox5.Text = rd.GetInt32("[taille de lot]")
imp.Show()
End While
Cn.Close()
Catch ex As SqlException
MessageBox.Show(ex.Message)
End Try
End Sub
当我检查我的专栏类型时,我总是遇到这个错误
System.InvalidCastException: 'La conversion de la chaîne "pk_veh" en type 'Integer' n'est pas valide.'FormatException: Input string was not in a correct format.
这里是我的专栏类型
pk_veh,[taille de lot] : int
名称、项目、版本:varchar[50]
这里是解决方案
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim rd As SqlDataReader
Try
Cn.Open()
Dim cmd As New SqlCommand("SELECT isnull(pk_veh,0)pk_veh, isnull(designation,'')designation, isnull(projet,'')projet, isnull(version,'')version, isnull(taille_de_lot,0)taille_de_lot from [Cutting software].dbo.vehicule WHERE designation = '" & Form1.ComboBox3.SelectedValue & "'", Cn)
rd = cmd.ExecuteReader
While rd.Read
imp.TextBox1.Text = rd.GetInt32(0)
imp.TextBox2.Text = rd.GetString(1)
imp.TextBox3.Text = rd.GetString(2)
imp.TextBox4.Text = rd.GetString(3)
imp.TextBox5.Text = rd.GetInt32(4)
End While
Cn.Close()
Catch ex As SqlException
MessageBox.Show(ex.Message)
End Try
imp.Show()
End Sub