VB.NET & System.Data.Odbc - Parameter Query (OleDbParameter) - How to learn Connector/NET ADO.NET component System.Data.Odbc namespace is the .NET Framework Data Provider for ODBC data source, Using the OdbcParameter for mapping to a DataSet column.
ShotDev Focus:
- VB.NET & System.Data.Odbc - Parameter Query (OleDbParameter)
Example
ParameterQuery.aspx
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.Odbc"%>
<%@ 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.Odbc.OdbcConnection
Dim objCmd As System.Data.Odbc.OdbcCommand
Dim strConnString,strSQL As String
strConnString = "DSN=mydatabase;UID=;PWD=;"
objConn = New System.Data.Odbc.OdbcConnection(strConnString)
objConn.Open()
'*** FOR INSERT ***'
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
"VALUES (?,?,?,?,?,?)"
objCmd = New System.Data.Odbc.OdbcCommand(strSQL,objConn)
With objCmd
.Parameters.Add(New OdbcParameter("@sCustomerID","C005"))
.Parameters.Add(New OdbcParameter("@sName","Weerachai Nukitram"))
.Parameters.Add(New OdbcParameter("@sEmail","[email protected]"))
.Parameters.Add(New OdbcParameter("@sCountryCode","TH"))
.Parameters.Add(New OdbcParameter("@sBudget","2000000"))
.Parameters.Add(New OdbcParameter("@sUsed","1000000"))
End With
objCmd.ExecuteNonQuery()
lblText.Text = "Record Insert Sucessful."
'*** FOR UPDATE ***'
'strSQL = "UPDATE customer SET Budget = ? " & _
'" WHERE CustomerID = ? "
'objCmd = New System.Data.Odbc.OdbcCommand(strSQL,objConn)
'With objCmd
' .Parameters.Add(New OdbcParameter("@sBudget","4000000"))
' .Parameters.Add(New OdbcParameter("@sCustomerID","C005"))
'End With
'objCmd.ExecuteNonQuery()
'*** FOR DELETE ***'
'strSQL = "DELETE FROM customer " & _
'" WHERE CustomerID = ? "
'objCmd = New System.Data.Odbc.OdbcCommand(strSQL,objConn)
'With objCmd
' .Parameters.Add(New OdbcParameter("@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


1careful…
…