VB前台和后台SQL数据库连接后,在进行添加和修改过程中出错,后台没有变化,详细下图,求大神帮助 35
PublicClass学生信息修改InheritsSystem.Windows.Forms.FormDimstrconnAsString="datasource=.\SQ...
Public Class 学生信息修改
Inherits System.Windows.Forms.Form
Dim strconn As String = "data source=.\SQLEXPRESS;initial catalog=jxj;user id=sa;password=jxj123;"
Dim objds As New Data.DataSet
Dim objda As SqlClient.SqlDataAdapter
Dim bingpage As BindingManagerBase
Dim cn As New SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Private Sub Button1_Click//是添加按钮(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Button1.Enabled = False
Button2.Enabled = True
TextBox1.ReadOnly = False
TextBox2.ReadOnly = False
TextBox3.ReadOnly = False
TextBox4.ReadOnly = False
RichTextBox1.ReadOnly = False
End Sub
Private Sub Button2_Click //是确定按钮(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Button1.Enabled = True
Dim sql As String
Dim m, n As String
TextBox2.Text = ""
TextBox3.Text = ""
RichTextBox1.Text = ""
m = Trim(ComboBox2.Text) & "-" & Trim(ComboBox3.Text) & "-" & Trim(ComboBox4.Text)
n = Trim(ComboBox5.Text) & "-" & Trim(ComboBox6.Text) & "-" & Trim(ComboBox7.Text)
sql = "insert into 学生表(学号,姓名,性别,院系名称,出生日期,入学时间,出生地,政治面貌,备注) values( '" & Trim(TextBox1.Text) & "','" & _
Trim(TextBox2.Text) & "','" & Trim(ComboBox1.Text) & "','" & Trim(TextBox3.Text) & "','" & _
Trim(m) & "','" & Trim(n) & "','" & Trim(TextBox4.Text) & "','" & _
Trim(ComboBox8.Text) & "','" & Trim(RichTextBox1.Text) & "')"
cn.ConnectionString = strconn
cn.Open()
cmd = New SqlClient.SqlCommand(sql, cn)
cmd.ExecuteNonQuery()
cmd.Dispose()
cn.Dispose()
Button1.Enabled = True
Button2.Enabled = False
End Sub
Private Sub Button3_Click//是修改按钮(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click DataGridView1.ReadOnly = False
End Sub
Private Sub Button4_Click//是修改中的确定按钮(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click DataGridView1.ReadOnly = True
objda.Update(objds)
End Sub
End Class
添加学生的信息时,直接跳出应用程序。没有报错,后台信息也没有被添加。
下图是在对学生信息修改时出现的错误:
我是不是哪里程序编写的有问题啊,求大神帮助,感激涕零。
现在又有头疼的问题了,我直接去修改SQL表中学生的信息,提示:
真是蛋疼,当初没连接时还可以随便修改,可是现在,二者不交互,不给修改,真是烦 展开
Inherits System.Windows.Forms.Form
Dim strconn As String = "data source=.\SQLEXPRESS;initial catalog=jxj;user id=sa;password=jxj123;"
Dim objds As New Data.DataSet
Dim objda As SqlClient.SqlDataAdapter
Dim bingpage As BindingManagerBase
Dim cn As New SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Private Sub Button1_Click//是添加按钮(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Button1.Enabled = False
Button2.Enabled = True
TextBox1.ReadOnly = False
TextBox2.ReadOnly = False
TextBox3.ReadOnly = False
TextBox4.ReadOnly = False
RichTextBox1.ReadOnly = False
End Sub
Private Sub Button2_Click //是确定按钮(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Button1.Enabled = True
Dim sql As String
Dim m, n As String
TextBox2.Text = ""
TextBox3.Text = ""
RichTextBox1.Text = ""
m = Trim(ComboBox2.Text) & "-" & Trim(ComboBox3.Text) & "-" & Trim(ComboBox4.Text)
n = Trim(ComboBox5.Text) & "-" & Trim(ComboBox6.Text) & "-" & Trim(ComboBox7.Text)
sql = "insert into 学生表(学号,姓名,性别,院系名称,出生日期,入学时间,出生地,政治面貌,备注) values( '" & Trim(TextBox1.Text) & "','" & _
Trim(TextBox2.Text) & "','" & Trim(ComboBox1.Text) & "','" & Trim(TextBox3.Text) & "','" & _
Trim(m) & "','" & Trim(n) & "','" & Trim(TextBox4.Text) & "','" & _
Trim(ComboBox8.Text) & "','" & Trim(RichTextBox1.Text) & "')"
cn.ConnectionString = strconn
cn.Open()
cmd = New SqlClient.SqlCommand(sql, cn)
cmd.ExecuteNonQuery()
cmd.Dispose()
cn.Dispose()
Button1.Enabled = True
Button2.Enabled = False
End Sub
Private Sub Button3_Click//是修改按钮(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click DataGridView1.ReadOnly = False
End Sub
Private Sub Button4_Click//是修改中的确定按钮(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click DataGridView1.ReadOnly = True
objda.Update(objds)
End Sub
End Class
添加学生的信息时,直接跳出应用程序。没有报错,后台信息也没有被添加。
下图是在对学生信息修改时出现的错误:
我是不是哪里程序编写的有问题啊,求大神帮助,感激涕零。
现在又有头疼的问题了,我直接去修改SQL表中学生的信息,提示:
真是蛋疼,当初没连接时还可以随便修改,可是现在,二者不交互,不给修改,真是烦 展开
3个回答
展开全部
objda.Update(objds[0])试一下,你这个语法很奇怪,没见过这样写的
没有sql语句,难道是对当前变量的修改显示不更新数据库吗?
没有sql语句,难道是对当前变量的修改显示不更新数据库吗?
更多追问追答
追问
这样写直接提示错误,“应为标识符”
追答
插入那个你应该设个断点调试一下,或者用try catch捕获一下异常
update这个真看不懂,你看看update方法需要什么类型的参数吧,我觉得应该是datatable的吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这句话什么意思?objda.Update(objds)objda和objds我都没找到啊
更多追问追答
追问
Dim objds As New Data.DataSet
Dim objda As SqlClient.SqlDataAdapter
这些在前面都是定义好的
追答
这两个对象在使用前是在什么地方初始化的?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询