vb.net连接access System.Data.OleDb.OleDbException 5
EndIfDimidAsInt16=0DimlbAsString=""DimpageAsInt16=0id=Request.QueryString("id")lb=Req...
End If
Dim id As Int16 = 0
Dim lb As String = ""
Dim page As Int16 = 0
id = Request.QueryString("id")
lb = Request.QueryString("lb")
page = Request.QueryString("page")
Dim myConn As Data.OleDb.OleDbConnection = New Data.OleDb.OleDbConnection
Dim strinst As String
Dim inst As Data.OleDb.OleDbCommand
myConn.ConnectionString = Application("connstr")
myConn.Open()
If id <> 0 Then
strinst = ""
strinst &= "update 新闻 set "
strinst &= "标题='" & Trim(TextBox2.Text) & "',"
strinst &= "内容='" & FreeTextBox1.Text & "',"
strinst &= "作者='" & Trim(TextBox1.Text) & "',"
If Not File1.PostedFile Is Nothing And File1.PostedFile.FileName <> "" Then
strinst &= "图片数=1,"
Else
strinst &= "图片数=0,"
End If
strinst &= "类别='" & DropDownList1.SelectedItem.Text & "'"
strinst &= " where id=" & id
Else
strinst = ""
strinst &= "insert into 新闻(标题,内容,作者,类别,发布日期,发布人,图片数,次数)values("
strinst &= "'" & Trim(TextBox2.Text) & "',"
strinst &= "'" & FreeTextBox1.Text & "',"
strinst &= "'" & Trim(TextBox1.Text) & "',"
strinst &= "'" & DropDownList1.SelectedItem.Text & "',"
strinst &= "'" & Today & "',"
strinst &= "'" & Session("name") & "',"
If Not File1.PostedFile Is Nothing And File1.PostedFile.FileName <> "" Then
strinst &= "1,"
Else
strinst &= "0,"
End If
strinst &= "1"
strinst &= ")"
End If
inst = New Data.OleDb.OleDbCommand(strinst, myConn)
inst.ExecuteNonQuery() 展开
Dim id As Int16 = 0
Dim lb As String = ""
Dim page As Int16 = 0
id = Request.QueryString("id")
lb = Request.QueryString("lb")
page = Request.QueryString("page")
Dim myConn As Data.OleDb.OleDbConnection = New Data.OleDb.OleDbConnection
Dim strinst As String
Dim inst As Data.OleDb.OleDbCommand
myConn.ConnectionString = Application("connstr")
myConn.Open()
If id <> 0 Then
strinst = ""
strinst &= "update 新闻 set "
strinst &= "标题='" & Trim(TextBox2.Text) & "',"
strinst &= "内容='" & FreeTextBox1.Text & "',"
strinst &= "作者='" & Trim(TextBox1.Text) & "',"
If Not File1.PostedFile Is Nothing And File1.PostedFile.FileName <> "" Then
strinst &= "图片数=1,"
Else
strinst &= "图片数=0,"
End If
strinst &= "类别='" & DropDownList1.SelectedItem.Text & "'"
strinst &= " where id=" & id
Else
strinst = ""
strinst &= "insert into 新闻(标题,内容,作者,类别,发布日期,发布人,图片数,次数)values("
strinst &= "'" & Trim(TextBox2.Text) & "',"
strinst &= "'" & FreeTextBox1.Text & "',"
strinst &= "'" & Trim(TextBox1.Text) & "',"
strinst &= "'" & DropDownList1.SelectedItem.Text & "',"
strinst &= "'" & Today & "',"
strinst &= "'" & Session("name") & "',"
If Not File1.PostedFile Is Nothing And File1.PostedFile.FileName <> "" Then
strinst &= "1,"
Else
strinst &= "0,"
End If
strinst &= "1"
strinst &= ")"
End If
inst = New Data.OleDb.OleDbCommand(strinst, myConn)
inst.ExecuteNonQuery() 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
数据库连接的几个步骤:
Dim myConn As OleDbConnection = New OleDbConnection '声明并实例化数据库连接对象
'数据库连接字符串(注意:这里假设数据库文件保存在D盘根目录中)
Dim myConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\数据库实例.mdb "
myConn.ConnectionString = myConnection '设置数据库连接对象的数据库连接字符串属性
myConn.Open() '打开数据库连接
Dim myConn As OleDbConnection = New OleDbConnection '声明并实例化数据库连接对象
'数据库连接字符串(注意:这里假设数据库文件保存在D盘根目录中)
Dim myConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\数据库实例.mdb "
myConn.ConnectionString = myConnection '设置数据库连接对象的数据库连接字符串属性
myConn.Open() '打开数据库连接
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询