Visual Basic .NET Forums    

Go Back   Visual Basic .NET Forums > Database > Database General Discussion

VB.NET Forums Newsletter Signup:
Email address:


Database General Discussion General discussion on database related topics

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-20-2008, 3:30 PM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Oct 2008
Posts: 47
Reputation: 5
Nader is on a distinguished programming path ahead
Question Select problem from DB Ms access to TextBox

I tried this code and it succeed only for one textbox but it didn't succeed for tow textboxes

Dim cmd AsNew OleDbCommand
cmd.Connection = conn
conn.Open()
cmd.CommandText = " SELECT Name,Place FROM TBaccount
TextBox1.Text = cmd.ExecuteScalar
TextBox2.Text = cmd.ExecuteScalar

conn.Close()

Reply With Quote
  #2 (permalink)  
Old 11-20-2008, 5:08 PM
VB.NET Forum Miyagee
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 431
Reputation: 89
MattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woods
Default

This process sounds lengthy but takes about 30 seconds.

Select Data --> Add New Data Source
Choose Database and click Next
Click the New Connection button
Click the Change button next to data source
---
If it's a .mdb file you can select Microsoft Access Database File and click OK
---
If it's a .accdb file select <other> from the Data source: list box
Select .NET Framework Data Provider for OLE DB
Click OK
Select Microsoft Office 12.0 Access Database Engine OLE DB Provider
---
Put the full path to your database in the Enter a server or file name: box
Click the Test Connection box to make sure everything is set up correctly.
Click OK
Click Next
Name your connection string something meaningful and click Next
Select the fields you want in your DataSet.
Name your DataSet
Click Finish

You should now have your DataSet in the Data Sources window. If you can't see it click Data --> Show Data Sources.

Click the name of the table in the data set and then click on the drop down arrow. Change it from DataGridView to Details.

Drag the table onto your form.

Visual Studio will create a BindingSource, TableAdapter, and BindingNavigator for you. You'll also see a label with the column name and textbox for each column in your DataSet.

Run your program. Enjoy writing 0 code.
Reply With Quote
  #3 (permalink)  
Old 11-21-2008, 8:23 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Oct 2008
Posts: 47
Reputation: 5
Nader is on a distinguished programming path ahead
Default

I'm using thie code in module and called from Sub. Your way will not service me.

Here is the solution

Dim sql AsString = "Select Name,Company FROM TBaccount"

Dim cmd AsNew OleDbCommand(sql, conn)
Dim dr As OleDbDataReader
conn.Open()
dr = cmd.ExecuteReader
DoWhile dr.Read
Form1.TextBox1.Text = dr("Name")
Form1.TextBox2.Text = dr("Company")
Reply With Quote
  #4 (permalink)  
Old 11-21-2008, 11:56 AM
VB.NET Forum Miyagee
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 431
Reputation: 89
MattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woodsMattP a notorious wonder 'round these woods
Default

/sigh...you can lead a horse to water.
Reply With Quote
  #5 (permalink)  
Old 11-28-2008, 10:38 PM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 64
Posts: 5,375
Reputation: 539
cjard VB.NET gold medalistcjard VB.NET gold medalistcjard VB.NET gold medalistcjard VB.NET gold medalistcjard VB.NET gold medalistcjard VB.NET gold medalistcjard VB.NET gold medalistcjard VB.NET gold medalistcjard VB.NET gold medalistcjard VB.NET gold medalistcjard VB.NET gold medalist
Default

Nader, take a read of the DW2 link in my signature, section "Creating a Simple Data App"

Quote:
Originally Posted by MattP
/sigh...you can lead a horse to water
__________________
"it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ
Reply With Quote
Reply

Bookmarks


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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 7:54 AM.




Click to advertise here

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
For advertising opportunities click here.