我的 into 语句错误有修复吗?

发布于 2025-01-13 16:02:33 字数 1966 浏览 2 评论 0原文

这是我的代码

    Private Sub Guna2Button1_Click(ByVal sender As System.Object, ByVal e As 
    System.EventArgs) Handles Guna2Button1.Click
    Dim pop As OpenFileDialog = New OpenFileDialog
    If pop.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
        Guna2CirclePictureBox1.Image = Image.FromFile(pop.FileName)
    End If
End Sub

Sub save()
    Try
        conn.Open()
        Dim cmd As New OleDb.OleDbCommand("insert into Table1('firstname','lastname','username','password','dob','role','status','pic') values(@firstname,@lastname,@username,@password,@dob,@role,@status,@pic)", conn)
        Dim i As New Integer
        cmd.Parameters.Clear()
        cmd.Parameters.AddWithValue("@firstname", Guna2TextBox1.Text)
        cmd.Parameters.AddWithValue("@lastname", Guna2TextBox2.Text)
        cmd.Parameters.AddWithValue("@username", Guna2TextBox3.Text)
        cmd.Parameters.AddWithValue("@password", Guna2TextBox4.Text)
        cmd.Parameters.AddWithValue("@dob", CDate(Guna2DateTimePicker1.Value))
        cmd.Parameters.AddWithValue("@role", Guna2ComboBox1.Text)
        cmd.Parameters.AddWithValue("@status", CBool(Guna2CheckBox2.Checked.ToString))

        'image convert to binary formate

        Dim FileSize As UInt32
        Dim mstream As New System.IO.MemoryStream
        Guna2CirclePictureBox1.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
        Dim picture() As Byte = mstream.GetBuffer
        FileSize = mstream.Length
        mstream.Close()

        cmd.Parameters.AddWithValue("@pic", picture)

        i = cmd.ExecuteNonQuery
        If i > 0 Then
            MsgBox("You are now a registered member.", vbInformation)

        Else
            MsgBox("Registration Failed. Try Again.", vbCritical)
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    conn.Close()
End Sub

,它说正确输入“名字”,但我做到了。它也是我的access数据库中相同的字段名称。我希望你能帮助我解决我的问题。我保证会做出回应。谢谢。

This is my code

    Private Sub Guna2Button1_Click(ByVal sender As System.Object, ByVal e As 
    System.EventArgs) Handles Guna2Button1.Click
    Dim pop As OpenFileDialog = New OpenFileDialog
    If pop.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
        Guna2CirclePictureBox1.Image = Image.FromFile(pop.FileName)
    End If
End Sub

Sub save()
    Try
        conn.Open()
        Dim cmd As New OleDb.OleDbCommand("insert into Table1('firstname','lastname','username','password','dob','role','status','pic') values(@firstname,@lastname,@username,@password,@dob,@role,@status,@pic)", conn)
        Dim i As New Integer
        cmd.Parameters.Clear()
        cmd.Parameters.AddWithValue("@firstname", Guna2TextBox1.Text)
        cmd.Parameters.AddWithValue("@lastname", Guna2TextBox2.Text)
        cmd.Parameters.AddWithValue("@username", Guna2TextBox3.Text)
        cmd.Parameters.AddWithValue("@password", Guna2TextBox4.Text)
        cmd.Parameters.AddWithValue("@dob", CDate(Guna2DateTimePicker1.Value))
        cmd.Parameters.AddWithValue("@role", Guna2ComboBox1.Text)
        cmd.Parameters.AddWithValue("@status", CBool(Guna2CheckBox2.Checked.ToString))

        'image convert to binary formate

        Dim FileSize As UInt32
        Dim mstream As New System.IO.MemoryStream
        Guna2CirclePictureBox1.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
        Dim picture() As Byte = mstream.GetBuffer
        FileSize = mstream.Length
        mstream.Close()

        cmd.Parameters.AddWithValue("@pic", picture)

        i = cmd.ExecuteNonQuery
        If i > 0 Then
            MsgBox("You are now a registered member.", vbInformation)

        Else
            MsgBox("Registration Failed. Try Again.", vbCritical)
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    conn.Close()
End Sub

It says type "firstname" correctly but I did. It is also the same field name in my access database. I hope you could help me with my problem. I promise to be responsive. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一向肩并 2025-01-20 16:02:33

另外,Password 是一个保留字:

"insert into Table1(firstname,lastname,username,[password],dob,role,[status],pic) values(@firstname,@lastname,@username,@password,@dob,@role,@status,@pic)"

并且 DateTimePicker 返回一个 DateTime 值:

cmd.Parameters.AddWithValue("@dob", Guna2DateTimePicker1.Value)
cmd.Parameters.AddWithValue("@status", Guna2CheckBox2.Checked)

Also, Password is a reserved word:

"insert into Table1(firstname,lastname,username,[password],dob,role,[status],pic) values(@firstname,@lastname,@username,@password,@dob,@role,@status,@pic)"

and DateTimePicker returns a DateTime value:

cmd.Parameters.AddWithValue("@dob", Guna2DateTimePicker1.Value)
cmd.Parameters.AddWithValue("@status", Guna2CheckBox2.Checked)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文