SELECT查询到STRING变量

时间:2015-11-03 01:31:33

标签: sql-server vb.net

我正在尝试创建一个表单,用户输入一个SerialNb,单击一个按钮,然后显示一个新表单,其中包含其余列,其中Table.SerialNbColumn = SerialNbInput

我会得到的错误是“表达式不会产生值”,我很严重,因为它很简单,但它实际上应该提供一个值。

Dim SQL As New SQLControl
//\\ **** USELESS CODES, ETC...

   Dim SynPayForm As New SynPaymentForm
   SynPayForm.DateFill = SQL.RunQuery("SELECT aDatePaid FROM SYNPaymentHistory WHERE SerialNb='" & SerialInput.Text & "' ")
   SynPayForm.SerialNbFill = SerialInput.Text
   SynPayForm.NameFill = SQL.RunQuery("SELECT FullName FROM SYNPaymentHistory WHERE SerialNb='" & SerialInput.Text & "' ")
   //\\ ** OTHER COLUMNS THAT HAVE SAME CONCEPT **
   SynPayForm.Show()

编辑:添加了SQLControl的功能

Public Class SQLControl
     Public SQLCon As New SqlConnection With {.ConnectionString = "Server=HOME\SQLEXPRESS;Database=Project Alpha1;User=sa;Pwd=patrick442;"}
     Public SQLCmd As SqlCommand
     Public SQLDA As SqlDataAdapter
     Public SQLDataset As DataSet

    Public Sub RunQuery(Query As String)
    Try
        SQLCon.Open()
        SQLCmd = New SqlCommand(Query, SQLCon)

        //\\ LOAD SQL RECORDS FOR DATAGRID
        SQLDA = New SqlDataAdapter(SQLCmd)
        SQLDataset = New DataSet
        SQLDA.Fill(SQLDataset)

        SQLCon.Close()
    Catch ex As Exception
        MsgBox(ex.Message)

        If SQLCon.State = ConnectionState.Open Then
            SQLCon.Close()

        End If
    End Try
End Sub

0 个答案:

没有答案