web 2.0

VB.NET & System.Data.OleDb - Parameter Query (OleDbParameter)

VB.NET & System.Data.OleDb - Parameter Query (OleDbParameter) - How to learn System.Data.OleDb namespace is the .NET Framework Data Provider for OLE DB data source, Using the OleDbParameter for mapping to a DataSet column (Microsoft Access (*.mdb) Database)

ShotDev Focus:
- VB.NET & System.Data.OleDb - Parameter Query (OleDbParameter)

Example

ParameterQuery.aspx

<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Page Language="VB" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
Sample1()
End Sub

Sub Sample1()

Dim objConn As System.Data.OleDb.OleDbConnection
Dim objCmd As System.Data.OleDb.OleDbCommand
Dim strConnString,strSQL As String

strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
Server.MapPath("database/mydatabase.mdb")&";Jet OLEDB:Database Password=;"
objConn = New System.Data.OleDb.OleDbConnection(strConnString)
objConn.Open()

'*** FOR INSERT ***'
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
"VALUES (@sCustomerID,@sName,@sEmail,@sCountryCode,@sBudget,@sUsed)"

objCmd = New System.Data.OleDb.OleDbCommand(strSQL,objConn)

'*** Sample 1 ***'
'With objCmd
'    .Parameters.AddWithValue("@sCustomerID","C005")
'    .Parameters.AddWithValue("@sName","Weerachai Nukitram")
'    .Parameters.AddWithValue("@sEmail","webmaster@shotdev.com")
'    .Parameters.AddWithValue("@sCountryCode","TH")
'    .Parameters.AddWithValue("@sBudget","2000000")
'    .Parameters.AddWithValue("@sUsed","1000000")
'End With

'*** Sample 2 ***'
With objCmd
.Parameters.Add(New OleDbParameter("@sCustomerID","C005"))
.Parameters.Add(New OleDbParameter("@sName","Weerachai Nukitram"))
.Parameters.Add(New OleDbParameter("@sEmail","webmaster@shotdev.com"))
.Parameters.Add(New OleDbParameter("@sCountryCode","TH"))
.Parameters.Add(New OleDbParameter("@sBudget","2000000"))
.Parameters.Add(New OleDbParameter("@sUsed","1000000"))
End With
objCmd.ExecuteNonQuery()

lblText.Text = "Record Insert Sucessful."

'*** FOR UPDATE ***'
'strSQL = "UPDATE customer SET Budget = @sBudget " & _
'" WHERE CustomerID = @sCustomerID "

'objCmd = New System.Data.OleDb.OleDbCommand(strSQL,objConn)
'With objCmd
'    .Parameters.Add(New OleDbParameter("@sBudget","4000000"))
'     .Parameters.Add(New OleDbParameter("@sCustomerID","C005"))
'End With
'objCmd.ExecuteNonQuery()

'*** FOR DELETE ***'
'strSQL = "DELETE FROM customer  " & _
'" WHERE CustomerID = @sCustomerID "

'objCmd = New System.Data.OleDb.OleDbCommand(strSQL,objConn)
'With objCmd
'    .Parameters.Add(New OleDbParameter("@sCustomerID","C005"))
'End With
'objCmd.ExecuteNonQuery()

objCmd = Nothing
objConn.Close()
objConn = Nothing

End Sub

</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="Server"></asp:Label>
</form>
</body>
</html>

Screenshot

VB.NET & System.Data.OleDb - Parameter Query (OleDbParameter)
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 10.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.