web 2.0

VB.NET & System.Data.Odbc - Parameter Query (OdbcParameter)

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","webmaster@shotdev.com"))
.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

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

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

One Response to “VB.NET & System.Data.Odbc - Parameter Query (OdbcParameter)”

  1. 1careful…

Leave a Reply

You must be logged in to post a comment.