mstester Posted March 21, 2007 Share 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. Link to comment Share on other sites More sharing options...
CoffeeFiend Posted March 22, 2007 Share Posted March 22, 2007 No such thing as msql. Do you mean MySQL or MSSQL (MS SQL Server)? Link to comment Share on other sites More sharing options...
mstester Posted March 22, 2007 Author Share Posted March 22, 2007 (edited) sorry my bad :s , MySQL Edited March 22, 2007 by mstester Link to comment Share on other sites More sharing options...
AndreVelloso Posted March 22, 2007 Share Posted March 22, 2007 SELECT * FROM [master].[dbo].[sysdatabases] Link to comment Share on other sites More sharing options...
mstester Posted March 23, 2007 Author Share 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 Link to comment Share on other sites More sharing options...
AndreVelloso Posted March 23, 2007 Share 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> Link to comment Share on other sites More sharing options...
mstester Posted March 27, 2007 Author Share 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 Link to comment Share on other sites More sharing options...
robert_nsu Posted July 26, 2007 Share 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now