473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

No database selected??

Hi everybody,

At the moment I'm trying to figure out how to access my local database
via C#. So far, I've succeeded in connecting and retrieving records. The
results are displayed in a datagrid.

However, when I load the results again, I get an error:
Unhandled Exception: Microsoft.Data.Odbc.OdbcException: ERROR [HY000]
[MySQL][MyODBC 5.00.11][MySQL] 1046 No database selected

Clearing the datagrid doesn't help (which is to be expected I suppose),
but I cannot fathom why it works the first time but never the second.
Could anybody please shed some light on this issue? What am I doing wrong
here?

Thanks!

Here is my code, it's executed whenever I press the "load" button:
/* code */
string myConnectionString =
"DSN=TgpCelebrity;UID=TgpCelebrity;PWD=tcAdmin ";
OdbcConnection MyConn;
OdbcCommand MyCmd = new OdbcCommand();
MyConn = new OdbcConnection(myConnectionString);
MyConn.Open();
MyCmd.Connection = MyConn;
StringBuilder SQL = new StringBuilder();
SQL.Append("SELECT ");
SQL.Append(" link ");
SQL.Append("FROM ");
SQL.Append(" links ");
MyCmd.CommandText = SQL.ToString();
OdbcDataReader result = MyCmd.ExecuteReader
(CommandBehavior.CloseConnection);
int nResultCount = 0;

DataTable table = new DataTable();
table.Columns.AddRange(
new DataColumn[]
{
new DataColumn("links", typeof(System.String))
}
);

object[] values = new object[1];

while (result.Read())
{
result.GetValues(values);
table.Rows.Add(values);
nResultCount++;
}
System.Console.WriteLine(nResultCount + " links found!");

table.AcceptChanges();
dataGrid1.SetDataBinding(table, null);

MyConn.Close();
/* end code */
Best regards,

Ikke
Apr 9 '07 #1
0 1260

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Coz | last post by:
Hi all, I'm looking for help again!!! I have been writing a page to update a database but now have another 'silly' problem with listbox's...Grrr... I'm trying to populate the list box with...
10
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from...
7
by: vsiat | last post by:
I am trying to create a treeview out of a database table with the typical structure ID, NAME, PARENTID, TYPE, EXTRA_INFO, where is linked to the . What I want to achieve is create a tree made...
1
by: jwright1 | last post by:
I am trying to set the selected value of a radio button list from a value stored in a table of a database. using vb codebehind asp.net. I tried binding the selected index item and selected index...
14
by: John Salerno | last post by:
Since the connect method of mysqldb requires a database name, it seems like you can't use it without having a database already created. So is there a way to connect to your mysql server (without a...
1
by: ghadley_00 | last post by:
Hi, I have a php form that encodes the responses to various <Select> field drop down menus as numbers (e.g. 0 to 50), and then posts the data to a MySQL table. I am trying to implement a form...
0
by: DxB | last post by:
Hello All i'm newbie here, was googling and found this site, it looks nice and i think i can learn a lot here, i have ms sql 2000 with 40 database and static public ip address. i am accessing...
10
by: patsman77 | last post by:
I hope this is the right spot to post this.... I am working on a form to pull the information from the database. I am trying to use arrays, but I only get one record to come back and it is...
1
suriacute85
by: suriacute85 | last post by:
Hi, I'm very new in web programming. i have afew question here. 1. i have a table which have a data, in 3 lines. now i want to save the data in the 3 lines into the database access. can i do that?...
4
by: sialater | last post by:
Hello, I realise there are a lot of topics related to this problem but many of what I have found has run cold or unresolved. What I have is an addressbook clone where there are groups which have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.