MySQL Connector/Net |
MySqlDataAdapter Constructor (String, MySqlConnection) |
MySqlDataAdapter Class Example See Also Send Feedback |
Namespace:
MySql.Data.MySqlClient
Assembly:
MySql.Data (in MySql.Data.dll) Version: 6.2.2.0
Syntax
C# |
---|
public MySqlDataAdapter( string selectCommandText, MySqlConnection connection ) |
Visual Basic (Declaration) |
---|
Public Sub New ( _ selectCommandText As String, _ connection As MySqlConnection _ ) |
Visual C++ |
---|
public: MySqlDataAdapter( String^ selectCommandText, MySqlConnection^ connection ) |
Parameters
- selectCommandText
- Type: System..::.String
A String that is a SQL SELECT statement or stored procedure to be used by the SelectCommand property of the MySqlDataAdapter.
- connection
- Type: MySql.Data.MySqlClient..::.MySqlConnection
A MySqlConnection that represents the connection.
Remarks
This implementation of the MySqlDataAdapter opens and closes a MySqlConnection if it is not already open. This can be useful in a an application that must call the Fill(DataSet) method for two or more MySqlDataAdapter objects. If the MySqlConnection is already open, you must explicitly call Close()()() or Dispose(Boolean) to close it.
When an instance of MySqlDataAdapter is created, the following read/write properties are set to the following initial values.
Properties | Initial Value |
---|---|
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
You can change the value of any of these properties through a separate call to the property.
Examples
Public Sub CreateSqlDataAdapter() Dim conn As MySqlConnection = New MySqlConnection("Data Source=localhost;" & _ "database=test") Dim da As MySqlDataAdapter = New MySqlDataAdapter("SELECT id, name FROM mytable", conn) da.MissingSchemaAction = MissingSchemaAction.AddWithKey da.InsertCommand = New MySqlCommand("INSERT INTO mytable (id, name) " & _ "VALUES (@id, @name)", conn) da.UpdateCommand = New MySqlCommand("UPDATE mytable SET id=@id, name=@name " & _ "WHERE id=@oldId", conn) da.DeleteCommand = New MySqlCommand("DELETE FROM mytable WHERE id=@id", conn) da.InsertCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id") da.InsertCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name") da.UpdateCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id") da.UpdateCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name") da.UpdateCommand.Parameters.Add("@oldId", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original da.DeleteCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original End Sub
public static void CreateSqlDataAdapter() { MySqlConnection conn = new MySqlConnection("Data Source=localhost;database=test"); MySqlDataAdapter da = new MySqlDataAdapter("SELECT id, name FROM mytable", conn); da.MissingSchemaAction = MissingSchemaAction.AddWithKey; da.InsertCommand = new MySqlCommand("INSERT INTO mytable (id, name) " + "VALUES (@id, @name)", conn); da.UpdateCommand = new MySqlCommand("UPDATE mytable SET id=@id, name=@name " + "WHERE id=@oldId", conn); da.DeleteCommand = new MySqlCommand("DELETE FROM mytable WHERE id=@id", conn); da.InsertCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id"); da.InsertCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name"); da.UpdateCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id"); da.UpdateCommand.Parameters.Add("@name", MySqlDbType.VarChar, 40, "name"); da.UpdateCommand.Parameters.Add("@oldId", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original; da.DeleteCommand.Parameters.Add("@id", MySqlDbType.VarChar, 5, "id").SourceVersion = DataRowVersion.Original; }