i use this code to connect to mysql database but how can i get the result in array and not in datagrid
I am better at c# than vb but I will break down your code so you see what it is doing I am better at c# than VB, I will walk through your code and tell you what it is doing. This may make it easier for you to change This is creating a string object "Dim strConn As String" This sets the value of the string to represent the parameters to connect to your db "strConn = "DRIVER={MySQL};SERVER=yourip;DATABASE=dbname;" & _ "USER=username;PASSWORD=pass; OPTION=3;"" Another string with your SQL query "Dim MySQL As String = "select * from Customers"" Here you are creating a connection object that will be used to connect to your db "Dim MyConn As New OdbcConnection(strConn)" You are now creating a dataset object. I do not knwo why you want an array, you can parse or bind this object to get what you want. A dataset houses rows, tables. You can think of them as a collection, similiar to an array. Dim ds As DataSet = New DataSet() This is the command you will send to theconnection Dim Cmd As New OdbcDataAdapter(MySQL, MyConn) This is when you populate the dataset. Set a breakpoint before and after and you can explore and axctually look at the data Cmd.Fill(ds, "Customers") This will be the code you replace. This is when you bind your dataset. If you want to maybe just parse through the dataset one row at a time and then just populate your webpage instead of using a grid you can do that. With components like a grid it is just less work. MyDataGrid.Datasource = ds.Tables("Customers").DefaultView MyDataGrid.DataBind() What are you trying to achieve with the array and I may be able to hep you. "
thank you gangwisch and cyberpope for your help but i keep getting this error: ExecuteReader requires an open and available Connection. The connection's current state is closed. i get the connection string from godaddy so i dont know where is the problem
Test the connection with a sql manager. If you have VS express it has one in it. What ide are\ you using? You probably have to execote teh connect method. I have not done vb since visual studio 6.0, I am all c#. Do you have any screen sharing programs? I coudl potentially help you debug it is we can set up screen sharing. I can send you code to connet to a godaddy MS SQL database, that works if you need it.
Here is some code I found online showing in vb how to do the pasrsing set variable to number of rows in dataset -1 since it starts at zero. Without the -1 you will get an error For X = 0 to DataSet.Tables(0).Rows.Count - 1 This code seems to just compare a columnname to itself. So I am assumign it is just showing you how to access the check it for some value for iteration purposes. If DataSet.Tables(0).Rows(X)("ColumnName").ToString = DataSet.Tables(0).Rows(X)("ColumnName").ToString Then 'Do stuff End If go to next row. Next X
Just making sure, she you set this code you place the actual database info srver, your uid and pwd in it correct? LOL strConn = "DRIVER={MySQL};SERVER=yourip;DATABASE=dbname;" & _ "USER=username;PASSWORD=pass; OPTION=3;"
Here is code frm microsft Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind") Dim selectCMD As SqlCommand = New SqlCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn) selectCMD.CommandTimeout = 30 Dim custDA As SqlDataAdapter = New SqlDataAdapter custDA.SelectCommand = selectCMD nwindConn.Open() Dim custDS As DataSet = New DataSet custDA.Fill(custDS, "Customers") nwindConn.Close() [C#] SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind"); SqlCommand selectCMD = new SqlCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn); selectCMD.CommandTimeout = 30; SqlDataAdapter custDA = new SqlDataAdapter(); custDA.SelectCommand = selectCMD; nwindConn.Open(); DataSet custDS = new DataSet(); custDA.Fill(custDS, "Customers"); nwindConn.Close(); You will change this to put in the godaddy soecifc connection info SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind"); It will be like this but with your uid and pwd I believe SqlConnection nwindConn = new SqlConnection("DRIVER={MySQL};SERVER=yourip;DATABASE=dbname;" & _ "USER=username;PASSWORD=pass; OPTION=3;" ); Change this section to have your query SqlCommand selectCMD = new SqlCommand("SELECT CustomerID, CompanyName FROM Customers", nwindConn); change this to your table name custDA.Fill(custDS, "Customers");