VB.NET & MySql.Data.MySQLClient - Parameter Query (OleDbParameter) - How to learn Connector/NET ADO.NET component MySql.Data.MySqlClient namespace is the .NET Framework Data Provider for MySql data source, Using the MySqlParameter for mapping to a DataSet column (MySQL Server Database)
ShotDev Focus:
- VB.NET & MySql.Data.MySQLClient - Parameter Query (OleDbParameter)
Example
ParameterQuery.aspx
<%@ Import Namespace="System.Data"%> <%@ Import Namespace="MySql.Data.MySqlClient"%> <%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Sample1() End Sub Sub Sample1() Dim objConn As MySql.Data.MySqlClient.MySqlConnection Dim objCmd As MySql.Data.MySqlClient.MySqlCommand Dim strConnString,strSQL As String strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false" objConn = New MySql.Data.MySqlClient.MySqlConnection(strConnString) objConn.Open() '*** FOR INSERT ***' strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _ "VALUES (?sCustomerID,?sName,?sEmail,?sCountryCode,?sBudget,?sUsed)" objCmd = New MySql.Data.MySqlClient.MySqlCommand(strSQL,objConn) With objCmd .Parameters.Add(new MySqlParameter("sCustomerID", "C005")) .Parameters.Add(new MySqlParameter("sName", "Weerachai Nukitram")) .Parameters.Add(new MySqlParameter("sEmail", "webmaster@shotdev.com")) .Parameters.Add(new MySqlParameter("sCountryCode", "TH")) .Parameters.Add(new MySqlParameter("sBudget", "2000000")) .Parameters.Add(new MySqlParameter("sUsed", "100000")) End With objCmd.ExecuteNonQuery() lblText.Text = "Record Insert Sucessful." '*** FOR UPDATE ***' 'strSQL = "UPDATE customer SET Budget = ?sBudget " & _ '" WHERE CustomerID = ?sCustomerID " 'objCmd = New MySql.Data.MySqlClient.MySqlCommand(strSQL,objConn) 'With objCmd ' .Parameters.Add(new MySqlParameter("sBudget", "4000000")) ' .Parameters.Add(new MySqlParameter("sCustomerID", "C005")) 'End With 'objCmd.ExecuteNonQuery() '*** FOR DELETE ***' 'strSQL = "DELETE FROM customer " & _ '" WHERE CustomerID = ?sCustomerID " 'objCmd = New MySql.Data.MySqlClient.MySqlCommand(strSQL,objConn) 'With objCmd ' .Parameters.Add(new MySqlParameter("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