mstester Posted March 21, 2007 Posted March 21, 2007 Hi guys,Ive a simple question for you all (well what i hope is a simple question ) Lets say I have a msql server with three databases created i.e. test, test_1 and test_3. Is there a way that I can display these three databases in a combo box? I want the user to be able to select which database he/she wishes to connect to. Im using VB.NET for this and any help would be really cool Thanks in advance.
CoffeeFiend Posted March 22, 2007 Posted March 22, 2007 No such thing as msql. Do you mean MySQL or MSSQL (MS SQL Server)?
mstester Posted March 22, 2007 Author Posted March 22, 2007 (edited) sorry my bad :s , MySQL Edited March 22, 2007 by mstester
mstester Posted March 23, 2007 Author Posted March 23, 2007 should the statement not beShow databases;See my problem is that i dont know how to populate the combobox with the result :S
AndreVelloso Posted March 23, 2007 Posted March 23, 2007 I quicky dit it in a Asp.Net / Vb.Net project: code for the page: <div> <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="name"> </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [name] FROM [master].[dbo].[sysdatabases] Order By [name]"></asp:SqlDataSource> </div> code for the web config: <connectionStrings> <add name="NorthwindConnectionString" connectionString="Data Source=SERVER2003;Initial Catalog=master;User ID=sa;Password=mysapassword" providerName="System.Data.SqlClient" /> </connectionStrings>
mstester Posted March 27, 2007 Author Posted March 27, 2007 (edited) Thanks for the help guys, I figured it out below is a snippet of the code:However now my problem is that I cant figure out a way to allow the user to connect to the database which they just selected, any ideas?? Note: The code is written very poorly Dim conn As MySqlConnection Dim myCommand As New MySqlCommand Dim myAdapter As New MySqlDataAdapter Dim dataset As New DataSet Dim SQL As String Dim myData As New DataTable conn = New MySqlConnection conn.ConnectionString = "server=*******;" & "user id=" & usernametxt.Text & ";" _ & "password=" & pwdtxt.Text & ";" Try conn.Open() MessageBox.Show("Connection Opened Successfully!") Catch myerror As MySqlException MessageBox.Show("Error was encountered when connecting" & myerror.Message) Finally End Try SQL = "Show Databases;" myCommand.Connection = conn myCommand.CommandText = SQL myAdapter.SelectCommand = myCommand myAdapter.Fill(myData) comboBox.DataSource = myData comboBox.DisplayMember = "Database" conn.Close() Edited March 27, 2007 by mstester
robert_nsu Posted July 26, 2007 Posted July 26, 2007 there is a mSQL. not to be rude or a smartass though. but i dont know of anyone that uses it.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now