请发表友善的回复…
发表回复
whatme168 2003-09-29
- 打赏
- 举报
Dim constr As String = "provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("../database/aaa.mdb")
Dim cn As OleDbConnection = New OleDbConnection(constr)
Dim sqlstr As String = "insert into xiangmubiao(title,introduce,leibie) values(?,?,?)"
Dim cmd As OleDbCommand = New OleDbCommand(sqlstr, cn)
cmd.Parameters.Add("title", OleDbType.VarChar, 32, "title")
cmd.Parameters.Add("sbody", OleDbType.VarChar, 5000, "sbody")
cmd.Parameters.Add("leibie", OleDbType.VarChar, 32, "leibie")
cmd.Parameters("title").Value = title.Text
cmd.Parameters("sbody").Value = sBody.Text
cmd.Parameters("leibie").Value = leibie.SelectedItem.Value
Try
cn.Open()
cmd.ExecuteNonQuery()
title.Text = ""
title.Text = ""
Response.Redirect("ok.aspx")
Response.End()
Catch ex As Exception
Response.Write(ex.Message)
Response.End()
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
这是我正写的一个提交程序,呵,,
Dim cn As OleDbConnection = New OleDbConnection(constr)
Dim sqlstr As String = "insert into xiangmubiao(title,introduce,leibie) values(?,?,?)"
Dim cmd As OleDbCommand = New OleDbCommand(sqlstr, cn)
cmd.Parameters.Add("title", OleDbType.VarChar, 32, "title")
cmd.Parameters.Add("sbody", OleDbType.VarChar, 5000, "sbody")
cmd.Parameters.Add("leibie", OleDbType.VarChar, 32, "leibie")
cmd.Parameters("title").Value = title.Text
cmd.Parameters("sbody").Value = sBody.Text
cmd.Parameters("leibie").Value = leibie.SelectedItem.Value
Try
cn.Open()
cmd.ExecuteNonQuery()
title.Text = ""
title.Text = ""
Response.Redirect("ok.aspx")
Response.End()
Catch ex As Exception
Response.Write(ex.Message)
Response.End()
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
这是我正写的一个提交程序,呵,,
NoReady 2003-09-29
- 打赏
- 举报
很多,最简单的一种,就像ADO一样用oledbcommand,如下为插入数据:
Dim conn As New OleDbConnection
With conn
.ConnectionString = ConnctionString
.Open()
End With
'execute the sql
strSql = "INSERT INTO ORDERET(OrderId, Company, Customer, CustManager, TotalQty, SaleType) VALUES ('0001', '" & Company & "', '" & Customer & "', '" & CustManager & "'," & TotalQty & "5, '" & SaleType & "')"
With cmd
.Connection = conn
.CommandType = CommandType.Text
.CommandText = strSql
.ExecuteNonQuery()
End With
cmd.Dispose()
Dim conn As New OleDbConnection
With conn
.ConnectionString = ConnctionString
.Open()
End With
'execute the sql
strSql = "INSERT INTO ORDERET(OrderId, Company, Customer, CustManager, TotalQty, SaleType) VALUES ('0001', '" & Company & "', '" & Customer & "', '" & CustManager & "'," & TotalQty & "5, '" & SaleType & "')"
With cmd
.Connection = conn
.CommandType = CommandType.Text
.CommandText = strSql
.ExecuteNonQuery()
End With
cmd.Dispose()