Binding to a table in an SQL Database.
Binding to a table in an SQL Database.
Binding to a table in an SQL Database.
Binding to a table in an SQL Database.
Binding to a table in an SQL Database.
Binding to a table in an SQL Database. Binding to a table in an SQL Database. Binding to a table in an SQL Database. Binding to a table in an SQL Database. Binding to a table in an SQL Database. Binding to a table in an SQL Database. Binding to a table in an SQL Database. Binding to a table in an SQL Database.
Binding to a table in an SQL Database. Binding to a table in an SQL Database.
Binding to a table in an SQL Database.
Go Back  Xtreme Visual Basic Talk > > > Binding to a table in an SQL Database.


Reply
 
Thread Tools Display Modes
  #1  
Old 09-17-2006, 07:26 PM
Mark McLeroy Mark McLeroy is offline
Regular
 
Join Date: May 2006
Posts: 50
Default Binding to a table in an SQL Database.


Hi All:
Please bear with me, I am very new.
This is what I am trying to do. I have an existing SQL database with multiple tables. I have SQL Server Express 2005 running a local machine (the database is also on the local machine). I am trying to bind a DataGrid to one of the tables in the database. Now this is what my connection string looks like:

m_cnSQLInventoryConnection.ConnectionString = _
"Provider=SQLOLEDB;Data Source=Computer Name\SQLEpress;Database=WASMPOS;User ID=XXXXXXX;Password=XXXXXXX"

This work! I log into the server sucessfully! Now how do I bind the DataGrid to a particular table in the database using only code (no data connecion wizards)? I kinda think it has to be specified when I create the DataAdaptor. Am I on the wrong track?

Any help you can give would be appreciated.

Thank you.

Mark McLeroy
Reply With Quote
  #2  
Old 09-17-2006, 08:21 PM
Mark McLeroy Mark McLeroy is offline
Regular
 
Join Date: May 2006
Posts: 50
Default

Sorry I posted this message in the wrong fourm. It should have gone the .net Database fourm. I have reposted there. Mediator please delete this message.

Thanks

Mark McLeroy
Reply With Quote
  #3  
Old 09-18-2006, 03:53 PM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

Hi

Are you using VS2005 or VS.Net? There are some subtle differences (some aren't that subtle) between the two.
Reply With Quote
  #4  
Old 09-18-2006, 05:11 PM
Mark McLeroy Mark McLeroy is offline
Regular
 
Join Date: May 2006
Posts: 50
Default

Quote:
Originally Posted by IUnknown
Hi

Are you using VS2005 or VS.Net? There are some subtle differences (some aren't that subtle) between the two.

I am using VS2005 Standard Edition.

Thanks.
Reply With Quote
  #5  
Old 09-19-2006, 08:33 AM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

There are newer versions of those controls, DataGridView for DataGrid and TableAdapter for DataAdapter.

The link on this post will lead you to heaps of walkthroughs and guides, including code examples on using these two new controls.
Reply With Quote
  #6  
Old 09-19-2006, 07:21 PM
Mark McLeroy Mark McLeroy is offline
Regular
 
Join Date: May 2006
Posts: 50
Default

Quote:
Originally Posted by IUnknown
There are newer versions of those controls, DataGridView for DataGrid and TableAdapter for DataAdapter.

The link on this post will lead you to heaps of walkthroughs and guides, including code examples on using these two new controls.
Thank you for your reply. I stated I need help with the DataGrid control I actually did indeed mean to type DataGridView.

Also these links are great and I will indeed go through them. However, though they did provide code samples, they seem to concentrate on wizards that Microsoft provides. My main problem with that is when I distribute the program I will not be sure where the database will be on the users system. It may even be on a mapped networked drive. I need the user to be able to browse for the database. When using a wizard, it binds to a database at an exact drive letter in an exact folder that the database was located at design time. If the database is not at that location at run time all heck breaks loose. Also, please correct me is I am wrong, but I don't think this holds true for SQL databases. I think the SQL server takes care of database location once the database is attached to the server.

Thanks Again.

Mark McLeroy
Reply With Quote
  #7  
Old 09-20-2006, 07:41 AM
Aquila's Avatar
Aquila Aquila is offline
Contributor
 
Join Date: Oct 2002
Location: Ocala, Fl.
Posts: 597
Default

Quote:
Originally Posted by Mark McLeroy
Thank you for your reply. I stated I need help with the DataGrid control I actually did indeed mean to type DataGridView.

Also these links are great and I will indeed go through them. However, though they did provide code samples, they seem to concentrate on wizards that Microsoft provides. My main problem with that is when I distribute the program I will not be sure where the database will be on the users system. It may even be on a mapped networked drive. I need the user to be able to browse for the database. When using a wizard, it binds to a database at an exact drive letter in an exact folder that the database was located at design time. If the database is not at that location at run time all heck breaks loose. Also, please correct me is I am wrong, but I don't think this holds true for SQL databases. I think the SQL server takes care of database location once the database is attached to the server.

Thanks Again.

Mark McLeroy

Plase A DataGridView Control on your form.
Then...

Code:
Dim strCNN as string = "Connection String Goes Here" Dim cnn As New System.Data.SqlClient.SqlConnection(strCNN) Dim ds As New DataSet cnn.Open() Dim dta As SqlDataAdapter = New SqlDataAdapter("Select * From SomeTable", cnn) dta.Fill(ds) dgv.DataSource = ds.Tables(0) cnn.Close()
__________________
Plotting to take over the world since 1978
Reply With Quote
  #8  
Old 09-20-2006, 09:35 AM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

Irrespective whether a wizard was used or not, you'd still have to provide the correct connectionstring for your app to work properly. If you step through your code as your app is starting up, you will see that at some point the connectionstring is used.
I used to use the windows registry to store connectionstring and other settings, but now I typically put them in the app.config (or web.config for web apps), where the values are accessible via My.Settings. Data in the app.config is not compiled into the exe and can be modified when deploying your app.
Reply With Quote
  #9  
Old 09-20-2006, 07:53 PM
Mark McLeroy Mark McLeroy is offline
Regular
 
Join Date: May 2006
Posts: 50
Default

I can't believe it.
3 books, countless Microsoft articals, hours searching the net...and these are the 8 simple lines of code I was looking for. They work PERFECTLY! Thank you all so much especially you Aquila.
I am sure I'll have more questions while developing this app, but for now thanks again all!

Speak to you soon.
Mark McLeroy
Reply With Quote
  #10  
Old 09-20-2006, 09:16 PM
Aquila's Avatar
Aquila Aquila is offline
Contributor
 
Join Date: Oct 2002
Location: Ocala, Fl.
Posts: 597
Default

Quote:
Originally Posted by Mark McLeroy
I can't believe it.
3 books, countless Microsoft articals, hours searching the net...and these are the 8 simple lines of code I was looking for. They work PERFECTLY! Thank you all so much especially you Aquila.
I am sure I'll have more questions while developing this app, but for now thanks again all!

Speak to you soon.
Mark McLeroy
We aim to please. Or at least not confuse too much. One or the other.
__________________
Plotting to take over the world since 1978
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Binding to a table in an SQL Database.
Binding to a table in an SQL Database.
Binding to a table in an SQL Database. Binding to a table in an SQL Database.
Binding to a table in an SQL Database.
Binding to a table in an SQL Database.
Binding to a table in an SQL Database. Binding to a table in an SQL Database. Binding to a table in an SQL Database. Binding to a table in an SQL Database. Binding to a table in an SQL Database. Binding to a table in an SQL Database. Binding to a table in an SQL Database.
Binding to a table in an SQL Database.
Binding to a table in an SQL Database.
 
Binding to a table in an SQL Database.
Binding to a table in an SQL Database.
 
-->