vb.net 中的 SQL 字符串错误
我想将数据库连接到我的项目 但我在这条线上收到错误
“数据源=.\SQLEXPRESS; AttachDbFilename =“c:\用户\cj\文档\视觉 工作室 2010\Projects\WindowsApplication1\WindowsApplication1\cj.mdf";集成 安全性=True;用户实例=True"
错误是 错误 1 字符常量必须恰好包含一个字符。
错误2 语法错误。
这是代码
Dim ms As New MemoryStream()
Me.PictureBox1.Image.Save(ms, Me.PictureBox1.Image.RawFormat)
Dim arraybuffer() As Byte = ms.GetBuffer
ms.Close()
Dim sqlString As String = "Data Source=.\SQLEXPRESS; AttachDbFilename="c:\\users\\cj\\documents\\visual studio 2010\\Projects\\WindowsApplication1\\WindowsApplication1\\cj.mdf";Integrated Security=True;User Instance=True"
Dim sqlQuery As String = "INSERT INTO image Values(@imagedata)"
Dim sqlcon As New SqlConnection(sqlString)
sqlcon.Open()
Dim sqlcmd As New SqlCommand(sqlQuery, sqlcon)
sqlcmd.Parameters.Add(New SqlParameter("@imagedata", arraybuffer))
MessageBox.Show("IMAGE SAVED IN DATABASE")
sqlcon.Close()
i want to connect a database to my project
but i am getting an error on this line
"Data Source=.\SQLEXPRESS;
AttachDbFilename="c:\users\cj\documents\visual
studio
2010\Projects\WindowsApplication1\WindowsApplication1\cj.mdf";Integrated
Security=True;User Instance=True"
the error is
Error 1 Character constant must contain exactly one character.
Error 2 Syntax error.
THIS IS THE CODE
Dim ms As New MemoryStream()
Me.PictureBox1.Image.Save(ms, Me.PictureBox1.Image.RawFormat)
Dim arraybuffer() As Byte = ms.GetBuffer
ms.Close()
Dim sqlString As String = "Data Source=.\SQLEXPRESS; AttachDbFilename="c:\\users\\cj\\documents\\visual studio 2010\\Projects\\WindowsApplication1\\WindowsApplication1\\cj.mdf";Integrated Security=True;User Instance=True"
Dim sqlQuery As String = "INSERT INTO image Values(@imagedata)"
Dim sqlcon As New SqlConnection(sqlString)
sqlcon.Open()
Dim sqlcmd As New SqlCommand(sqlQuery, sqlcon)
sqlcmd.Parameters.Add(New SqlParameter("@imagedata", arraybuffer))
MessageBox.Show("IMAGE SAVED IN DATABASE")
sqlcon.Close()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用双双引号(
""
)在字符串中转义双引号("
)。试试这个
You have to escape double quotes (
"
) in string with double double quotes(""
).Try this