标题:未处理的“System.Data.OleDb.OleDbException 达人进来帮下忙
只看楼主
wjq
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-4-8
 问题点数:0 回复次数:4 
未处理的“System.Data.OleDb.OleDbException 达人进来帮下忙

Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
If btnadd.Text = "Add" Then
txtid.Text = ""
txtname.Text = ""
txttelno.Text = ""
txtaddress.Text = ""
txtemail.Text = ""
btnadd.Text = "Confirm"
MessageBox.Show("Add the information and then Click the confirm", "check", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If


If btnadd.Text = "Confirm" Then
Dim currentPos As Integer = ps.Position
If MessageBox.Show("Are you sure to add", "Confirm", MessageBoxButtons.OKCancel) = DialogResult.OK Then
Dim id As String = "'" & txtid.Text & "'"
Dim name As String = "'" & txtname.Text & "'"
Dim telno As String = "'" & txttelno.Text & "'"
Dim Address As String = "'" & txtaddress.Text & "'"
Dim Email As String = "'" & txtemail.Text & "'"

Dim addstr As String
addstr = "insert into Company(companyID,companyName,telNo,address,email) values("
addstr = addstr & id & "," & name & "," & telno & "," & Address & "," & Email & ")"
OleDbConnection1.Open()
OleDbDataAdapter1.InsertCommand.CommandText = addstr
OleDbDataAdapter1.InsertCommand.ExecuteNonQuery()这句错误
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11)
ps.Position = ps.Count - 1
OleDbConnection1.Close()
Else
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11)
ps.Position = currentPos
End If
btnadd.Text = "Add"

End If
End Sub

请达人帮看看哪里错了.我是新手..一直找不出哪里错了.

搜索更多相关主题的帖子: System Data OleDb Text 
2007-04-08 18:22
Kendy123456
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:62
帖 子:2720
专家分:0
注 册:2007-1-3
得分:0 
代码不全 错误信息也没给

可能是2种情况
1。 Adapter没有实例化 使用前要new
2。 addstr拼成的sql语句有错误 设个断点 把addstr的值拿出来 放到数据库下面取run 看看是不是报错

2007-04-10 09:51
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
得分:0 
addstr = "insert into Company(companyID,companyName,telNo,address,email) values("
addstr = addstr & id & "," & name & "," & telno & "," & Address & "," & Email & ")"
你这里错了吧?
我想你的 address,email 等列都是字符型的吧..而你后面单引号都没有....这个能执行过吗?

飘过~~
2007-04-10 12:32
wjq
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-4-8
得分:0 
addstr = "insert into Company(companyID,companyName,telNo,address,email) values(" & id & ",'" & name & "'," & telno & ",'" & Address & "','" & Email & "')" 改成这样有单引号的还是不行...
哪位高手帮改下正确的sql insert 语句.谢谢.
2007-04-11 20:45
Kendy123456
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:62
帖 子:2720
专家分:0
注 册:2007-1-3
得分:0 
不用加单引号 你给id name赋值的时候 已经预先把单引号加进去了

断点断一下 看看addstr最后的值是什么

2007-04-12 09:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-130183-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.191608 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved