请问VB.NET和SQL数据库的这个连接怎么做?
在做一个VB.NET的作业,要求在后台数据库"students.mdb"中的表"学生"中通过SQL语句增加数据,请问该用什么代码?我从书上抄的代码用Visualstudi...
在做一个VB.NET的作业,要求在后台数据库"students.mdb"中的表"学生"中通过SQL语句增加数据,请问该用什么代码? 我从书上抄的代码用Visual studio2005编译能过,执行也能过,但是执行过后却没有对数据库有任何的影响(也就是说输不进去)我的代码如下,请高人帮帮忙啊: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim jidian As String jidian = (TextBox3.Text - "50" / "10") Dim strconn As String = "provider=Microsoft.jet.oledb.4.0;Data Source = students.mdb" Dim objconn As New OleDbConnection(strconn) Dim objadap As New OleDbDataAdapter() Dim objdset As New DataSet() Dim insertsql As String insertsql = "insert into " + ComboBox1.Text + "(姓名,学号,分数,绩点) values(" + "@" + TextBox1.Text + "," + "2" + TextBox2.Text + "," + "2" + TextBox3.Text + "," + "@" + jidian + ")" objconn.Open() objadap.SelectCommand = New OleDbCommand(insertsql, objconn) objconn.Close() objdset.Clear() MsgBox("导入成功", , "恭喜") End Sub
展开
1个回答
展开全部
楼主式式把button的click的代码改成下面的成不成 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim jidian As String jidian = (TextBox3.Text - "50" / "10") Dim strconn As String = "provider=Microsoft.jet.oledb.4.0;Data Source = students.mdb" Dim objconn As New OleDbConnection(strconn) Dim insertsql As String insertsql = "insert into " + ComboBox1.Text + "(姓名,学号,分数,绩点) values(" + "@" + TextBox1.Text + "," + "2" + TextBox2.Text + "," + "2" + TextBox3.Text + "," + "@" + jidian + ")" Dim objcmd As New OleDbCommand(insertsql, objconn) objconn.Open() objcmd.ExecuteNonQuery() objconn.Close() MsgBox("导入成功", , "恭喜") End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询