ASP.NET System.Data.Odbc - Parameter Query (OdbcParameter) |
ASP.NET System.Data.Odbc - Parameter Query() การเขียน ASP.NET ใช้งาน NameSpace System.Data.Odbc กับ Parameter Query() - OdbcParameter() เพื่อกำหนดคุณสมบัติของพารามิเตอร์ที่จะทำการโยนค่าให้กับ Statement
Instance NameSpace
VB.NETImports System.Data
Imports System.Data.Odbc
Language Code : VB.NET || C#
OdbcParameter Syntax
Dim QueryString As String = "SELECT * FROM Table1 WHERE Field1 LIKE ?"
Dim Cmd As OdbcCommand = New OdbcCommand(QueryString, Connection)
Cmd.Parameters.Add("?p1", OdbcType.VarChar, 3).Value = "a"
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 = lblText.Text & "- Record Inserted"
'*** 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>ThaiCreate.Com ASP.NET - System.Data.Odbc</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="Server"></asp:Label>
</form>
</body>
</html>
Screenshot
OdbcType
OdbcType.BigInt
OdbcType.Binary
OdbcType.Bit
OdbcType.Char
OdbcType.DateTime
OdbcType.Decimal
OdbcType.Numeric
OdbcType.Double
OdbcType.Image
OdbcType.Int
OdbcType.NChar
OdbcType.NText
OdbcType.NVarChar
OdbcType.Real
OdbcType.UniqueIdentifier
OdbcType.SmallDateTime
OdbcType.SmallInt
OdbcType.Text
OdbcType.Timestamp
OdbcType.TinyInt
OdbcType.VarBinary
OdbcType.VarChar
OdbcType.Date
OdbcType.Time
ASP.NET - Transaction
ตัวอย่างการเขียน .NET ร่วมกับ Parameter
Go to : ASP.NET Access BLOB Binary Data and Parameterized Query
Go to : ASP.NET MySQL BLOB Binary Data and Parameterized Query
Go to : ASP.NET SQL Server BLOB Binary Data and Parameterized Query
Go to : ASP.NET Oracle BLOB Binary Data and Parameterized Query
|