Hello:
I found an article to help me get connected to MySQL. (Using MySQL for testing only. Will eventually use MSSQL). http://www.c-sharpcorner.com/UploadFile/iamibohal/339/Default.aspx
It has a line: GridView1.DataBind();
Seems that that .DataBind() is not right. Can someone tell me what it should be or what I am missing?
Loading
Kirtan PatelPosted Mar 2, 2010, 7:43 PM
private void buttoTest_Click(object sender, EventArgs e)
{
try
{
MySqlConnection TestConnection = new MySqlConnection();
TestConnection.ConnectionString = "Data Source=localhost;Database= icepack;User ID=Demo;Password=Demo";
TestConnection.Open();
//
MySqlDataAdapter TestDataAdapter = new MySqlDataAdapter("SELECT * FROM Company", TestConnection);
DataSet TestDataSet = new DataSet();
//
TestDataAdapter.Fill(TestDataSet);
dataGridViewCompany.DataSource = TestDataSet.Tables[0];
//dataGridViewCompany.Bind(); // <<<< ERROR
MessageBox.Show("Got here...MySQL");
}
catch (SqlException SQLExecute)
{
MessageBox.Show("Can not connect to TestConnection...\r\r" + SQLExecute, "Test Connection...", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
theLizardPosted Mar 2, 2010, 8:58 PM
GustavoPosted Mar 2, 2010, 8:00 PM
YES... It worked. I had to get rid of something that I put in the properties.
Now I can work on the MSSQL ConnectionString version. I used the MySQL because it was easier to connect to. I have to do some configurations to the MSSQL server so it will allow me access it.
Kirtan PatelPosted Mar 2, 2010, 7:53 PM
its necessary in ASP.net but in windows application no need of it :)
The article you seen is for asp.net so they called Bind() method ..no need in Windows Application
GustavoPosted Mar 2, 2010, 7:51 PM
Thanks for your help. I changed the line to what you recommended.
BUT: Should I put back in the "dataGridViewCompany.Bind();" so it populated the dataGridViewCompany?
It has an issue with the "Bind".
GustavoPosted Mar 2, 2010, 7:27 PM
Here is the code I have so far:
private void buttoTest_Click(object sender, EventArgs e)
{
try
{
MySqlConnection TestConnection = new MySqlConnection();
TestConnection.ConnectionString = "Data Source=localhost;Database= icepack;User ID=Demo;Password=Demo";
TestConnection.Open();
//
MySqlDataAdapter TestDataAdapter = new MySqlDataAdapter("SELECT * FROM Company", TestConnection);
DataSet TestDataSet = new DataSet();
//
TestDataAdapter.Fill(TestDataSet);
dataGridViewCompany.DataSource = TestDataSet;
//dataGridViewCompany.Bind(); // <<<< ERROR
MessageBox.Show("Got here...MySQL");
}
catch (SqlException SQLExecute)
{
MessageBox.Show("Can not connect to TestConnection...\r\r" + SQLExecute, "Test Connection...", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
theLizardPosted Mar 2, 2010, 6:30 PM
There is an enormous differences between the Sql.Data provider and the MySql Connector which is what you would need.
There are differences between MSSQL and MySql calling conventions, so why are you learning something that you know you are not going to use! I am completely baffled.
Finaly there is a website you can go to to get ALL you connection strings for ANY database or xl or txt or jet or ole or odbc connectionstrings.com try it .