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 er开发者_运维百科ror 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()
You have to escape double quotes ("
) in string with double double quotes( ""
).
Try this
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"
精彩评论