Re: Need help with managing DB from code!
I set some breakpoints and checked the compiler reading the code line by line. When it came to foreach, it just checked the arguments and went on to the end of the block without reading the code inside the block. I guess that means there should be no tables in the DB, but I've got two tables, with columns and rows. And no, you're not adding items to the ComboBox in .Net 3.5 in a different way than what you has shown.
Re: Need help with managing DB from code!
alternativly you can use this sql statement to query sql server dictionary to find tables in your database:
Code:
select [name] as [Table_name] from sysobjects where type = 'U'
Touraj Ebrahimi [toraj_e] [at] [yahoo] [dot] [com]
Re: Need help with managing DB from code!
Quote:
Originally Posted by Guitarcomet
...block without reading the code inside the block. I guess that means there should be no tables in the DB, but I've got two tables, with columns and rows. ...
Whats about showing your code you already have created so we may have a look on it ;)
Re: Need help with managing DB from code!
Well, actually I haven't created any code before I started this thread. And after that I've told you what I've done. So, I'm just using another table to see what tables the database contains. Here's the code I'm using for it:
SqlConnection cn = new SqlConnection(connection);
cn.Open();
SqlCommand comm = new SqlCommand("SELECT * FROM Tables", cn);
SqlDataReader reader = comm.ExecuteReader
(CommandBehavior.CloseConnection);
int i = 0;
while (reader.Read())
{
try
{
comboBox1.Items.Add(reader.GetString(i));
}
catch
{
break;
}
i++;
}
cn.Close();
This is for reading from the table which holds information about all other tables. That's the code that I use.
Re: Need help with managing DB from code!
the problem with using that method is that, now, you are going to have to remember everytime you create a new table, you are going to have to add it to that table. that might be fine for the next couple of weeks, but in 6 months, you might not remember.
1 Attachment(s)
Re: Need help with managing DB from code!
Hi Guitarcomet !
Have you set the name of your Database as the name in restriction[0] ?
Anyway, as you obviously have some troubles to get it working maybe of some errors duplicating eclipsed4utoo s great example I have added a zip containing a full example.
I used Northwind database in SQL2005 Express Server so you only need to change your connection string and you will hav it working.
BTW I used a separate class for the database connection as you will see
Re: Need help with managing DB from code!
Yeah, now it did work! According to Visual Studio the owner name of the DB should not be dbo, so I changed to what Visual Studio said was the DB Owner, which was not correct. I apologize for that I didn't found out that earlier. Thanks to both eclipsed4utoo and JonnyPoet.