On Tue, Mar 29, 2011 at 9:29 PM, wy <[email protected]> wrote:
> Hi,
>
> I have a VB 2010 project which will connect to a MySQL database. When
> I add some new tables to the database, I also refresh the project data
> source to add the new added tables into project. After the tables
> added, I add a BindingSouce object into a Winform. I select the
> DataSource as Project's DataSource and wish to select the new added
> tables from the "Member" property but the list of data member does not
> include the new added table. I double check the project DataSource
> the new tables has been included. I wish to know is there anything I
> need to do to made the BindingSource object to "know" there are new
> tables added into project?
>
------------------------
Make a new Class for Data Access DAL
In it make multiple fuctions that do the connections for you as used below:
//define the connection reference and initialize it
MySql.Data.MySqlClient.MySqlConnection msqlConnection = null;
msqlConnection = new
MySql.Data.MySqlClient.MySqlConnection(“server=localhost;user
id=UserName;Password=UserPassword;database=DatabaseName;persist
security info=False”);
//define the command reference
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new
MySql.Data.MySqlClient.MySqlCommand();
//define the connection used by the command object
msqlCommand.Connection = this.msqlConnection;
//define the command text
msqlCommand.CommandText = "SELECT * FROM TestTable;";
try
{
//open the connection
this.msqlConnection.Open();
//use a DataReader to process each record
MySql.Data.MySqlClient.MySqlDataReader msqlReader =
msqlCommand.ExecuteReader();
while (msqlReader.Read())
{
//do something with each record
}
}
catch (Exception er)
{
//do something with the exception
}
finally
{
//always close the connection
this.msqlConnection.Close();
}
Can you see the reusable code above for multiple requests for data?
Have a method for Connection:
MySql.Data.MySqlClient.MySqlConnection msqlConnection = null;
msqlConnection = new
MySql.Data.MySqlClient.MySqlConnection(“server=localhost;user
id=UserName;Password=UserPassword;database=DatabaseName;persist
security info=False”);
//define the command reference
another for Command:
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new
MySql.Data.MySqlClient.MySqlCommand();
//define the connection used by the command object
msqlCommand.Connection = this.msqlConnection;
//define the command text
Then using that returned command object you can fill in what you want it to do:
msqlCommand.CommandText = "SELECT * FROM TestTable;";
--
Stephen Russell
901.246-0159 cell
--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net