Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

vb.net database

Posted on 2004-10-21
8
Medium Priority
?
199 Views
Last Modified: 2010-04-17
I am using the following code, it is connected to an access database. I am lost on how to now take the connection and tie it to a textbox, then when the use adds data to the textbox having a button to update the access database. I am using a style that I have always been familiar with and would like to continue using:


con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "database.mdb; Jet OLEDB:Database Password="
con.Open()
cmd.Connection =con
cmd.CommandText = "Select * from Table1"
dataadapter.selectcommand = cmd
dataadapter.Fill(dataset1, "Table1")


now what should I do I tried this:
 txtnames.Text = (dataset1.Tables("Table1").Rows(0).Item(dataset1.Tables("Table1").Columns(0)))


and it did put the data inside the textbox and then I just create a button that had an UPDate sql command that just looked at the textboxes and updated records. The problem is that if the field is blank(null) the programs pops up an error, also I do not know if this is the best way to do what I need it to do. So please show some code to get me what I need to complete this project I am working on.

Thanks

0
Comment
Question by:hogan9111
  • 4
  • 3
8 Comments
 

Author Comment

by:hogan9111
ID: 12369737
would this be the way to have the data from the database go into certain textboxes


 txtname.DataBindings.Add("Text", dataset1.Tables ("Table1"), "Name")
0
 

Accepted Solution

by:
Kindaian earned 200 total points
ID: 12370391
instead of:

 txtnames.Text = (dataset1.Tables("Table1").Rows(0).Item(dataset1.Tables("Table1").Columns(0)))

use:

 txtnames.Text = "" & (dataset1.Tables("Table1").Rows(0).Item(dataset1.Tables("Table1").Columns(0)))

That will avoid the "null" error because concatenation of a string with a null will return the string... (that way you won't use any data bind...)
0
 

Author Comment

by:hogan9111
ID: 12370744
Is it better to use this method:

 txtnames.Text = "" & (dataset1.Tables("Table1").Rows(0).Item(dataset1.Tables("Table1").Columns(0)))

or this:

txtname.DataBindings.Add("Text", dataset1.Tables ("Table1"), "Name")

also what exactly is the databindings
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:Daywalker46410
ID: 12375560
As for catching errors, you can either pre-check the textbox for empty values:

If txtnames.Text.Trim = "" Then
    ' Scold the user however you like
Else
    ' Update the dataset.

You can also put the Update code in a Try..Catch..Finally block and create a specific Catch for the DBNull error.
0
 

Author Comment

by:hogan9111
ID: 12381010
Is it better to use this method:

 txtnames.Text = "" & (dataset1.Tables("Table1").Rows(0).Item(dataset1.Tables("Table1").Columns(0)))

or this:

txtname.DataBindings.Add("Text", dataset1.Tables ("Table1"), "Name")

also what exactly is the databindings
0
 

Author Comment

by:hogan9111
ID: 12469046
anyone there
0
 

Expert Comment

by:Kindaian
ID: 12470697
Data bind is a way to "link" a controler to a database so that updates to the record are reflected to the database.

It is most usefull for simple, i mean very simple, data insertion/update.

It is a question on where you place the code to retrieve/store the data in the database. I prefer to have a function to get/set the data in a central way and in "my" code, so i can manipulate the data in the forms at my will before storing it in the database.

But, that is my option... there are "style" consideration here... There will be lots of other developers that have diferent views...
0
 

Expert Comment

by:Kindaian
ID: 12731870
Thanx for the award ;)

[it was btw my first answer in the site hehehe]
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question