请大家帮忙看看!为什么连接SQL数据库会出现初始化字符串不符合规范的有关问题
请大家帮忙看看!为什么连接SQL数据库会出现初始化字符串不符合规范的问题?
我自己写了一个连接SQL数据库的登录界面,但每次运行都会弹出“从索引39处时开始,初始化字符串的格式不符合规范”,我的数据库里的表(Users)只有cName和cCode两个元素,都是设的Char类型。
我的代码是:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim SQLConn As String = "Data Source=0F350777835F472;User ID=sa;password= " ";Initial Catalog=Viragon " & "Connect Timeout=30;Integrated Security=False "
Dim Conn As SqlConnection = New SqlConnection(SQLConn)
Conn.Open()
Dim cmdCommand As SqlCommand = New SqlCommand( "Select * from Users where cName= ' " & TextBox1.Text & " 'and cCode= ' " & TextBox2.Text & " 'and IsValid=1 ", Conn)
cmdCommand.CommandTimeout = 10
Dim myReader As SqlDataReader
myReader = cmdCommand.ExecuteReader()
If myReader.Read() Then
Dim form2 As New Form2
Me.Hide()
form2.ShowDialog() '这里是 showdialog ,不是 show !!!!!
Me.Close()
Else
MessageBox.Show( "登录失败!请重新输入! ", "信息提示 ", MessageBoxButtons.OK)
End If
Conn.Close()
myReader.Close()
Catch e1 As Exception
MessageBox.Show(e1.Message)
End Try
我自己写了一个连接SQL数据库的登录界面,但每次运行都会弹出“从索引39处时开始,初始化字符串的格式不符合规范”,我的数据库里的表(Users)只有cName和cCode两个元素,都是设的Char类型。
我的代码是:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim SQLConn As String = "Data Source=0F350777835F472;User ID=sa;password= " ";Initial Catalog=Viragon " & "Connect Timeout=30;Integrated Security=False "
Dim Conn As SqlConnection = New SqlConnection(SQLConn)
Conn.Open()
Dim cmdCommand As SqlCommand = New SqlCommand( "Select * from Users where cName= ' " & TextBox1.Text & " 'and cCode= ' " & TextBox2.Text & " 'and IsValid=1 ", Conn)
cmdCommand.CommandTimeout = 10
Dim myReader As SqlDataReader
myReader = cmdCommand.ExecuteReader()
If myReader.Read() Then
Dim form2 As New Form2
Me.Hide()
form2.ShowDialog() '这里是 showdialog ,不是 show !!!!!
Me.Close()
Else
MessageBox.Show( "登录失败!请重新输入! ", "信息提示 ", MessageBoxButtons.OK)
End If
Conn.Close()
myReader.Close()
Catch e1 As Exception
MessageBox.Show(e1.Message)
End Try