请大家帮忙看看!为什么连接SQL数据库会出现初始化字符串不符合规范的问题?

jetandcg 2007-09-12 04:24:54
我自己写了一个连接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


End Sub

End Class

大家能帮我看看是哪里出的问题吗?谢谢!
...全文
143 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jetandcg 2007-09-12
  • 打赏
  • 举报
回复
呵呵!谢谢提醒!

我把以下代码该了一下就可以了。
Dim SQLConn As String = "Data Source=0F350777835F472;" & "User ID=sa;" & "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 & "'", Conn)
iseelxj 2007-09-12
  • 打赏
  • 举报
回复
password=" & "

16,718

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧