To answer your first question here is some code/pseudocode for
updating to the database.

public void update(int customerNumber, string address, string city,
string state, string zip)
{
   //declare a new table adapter
   Adapters.TableAdapter1 ta = new Adapters.TableAdapter1();
   // pass the values to the update statement.
   ta.Update(customerNumber, address, city, state, zip);
}

To answer your second question, you end up defining the type of the
@param variable when you open the Parameters Collection Editor (inside
the table adapters property area).  This information is then stored in
the machine generated code area of the dataset.  IIRC the scope of the
@param variable is at the query level. So you will need to get the
value of the customer num text box again for the update query.

On Mar 22, 12:48 am, new db dvlpr <aronb2...@gmail.com> wrote:
> Well, I did do quite a bit of internet searching. But I have not been
> able to find the answer to the one small thing I am looking for. I am
> most familiar with the GUI way (with the dataset in designer mode
> etc.) and that is the method I am using in this case. I was pretty
> sure on what the update query under a tableadapter in the dataset
> would look like. But I am not sure how to pass the user's input values
> into this query.
>
> To explain better, I will just outline the main steps I have taken.
>
> After creating the visual basic project, I went into Data on the top
> menu and "Add New Data Source". After going through that wizard and
> selecting the appropriate objects from the SQL Server 2005 database
> (i need just the tables from the database), I binded certain fields to
> some controls on the form. After that I go into dataset in designer
> mode. In there I have first added a query to one tableadapter to
> search and retrieve a single record. This query looks like "SELECT
> Lname, Fname From Customer WHERE CustomerNum = @cnum". Notice this is
> a parameterized query. In the VB code behind a button control, there
> is code something like "Me.CustomerTableAdapter.FillBy
> (Me.TestDB.Customer, txtCustomerNum.Text)". So this statement passes
> the user's input back into the query to search for that one particular
> record. So that works fine.
>
> Now for the Update, I added a query that looks something like "UPDATE
> Customer SET Address = @addres, City = @city, State = @state, Zip =
> @zip WHERE CustomerNum = @cnum". Now from here on is where I am
> confused.
>
> When the user enters some values into the address, city, state, and
> zip textboxes and then clicks "Update" button, these user entered
> values need to passed back into the query. The update query needs to
> update the dataset and then in turn the the appropriate values in the
> right table in the SQL Server database need to be updated. I can't
> figure out how to pass the values in the textboxes on the form into
> the update query. Also I need to pass the "CustomerNum" value that the
> user searched with earlier to search for a particular record so that
> the correct record is updated. I have searched a lot but can not find
> out the syntax for the statement to pass those values to the update
> query.
>
> Also I do have another concept type question, when there is the @param
> in a parameterized query, what kind of variable is "@param" and how
> come it does not need to be declared first? Also with this @param,
> what is the scope of it? Is it valid only within that query or within
> a tableadapter...? With what I am trying to do for example, I have two
> querys. One is a SELECT and the other is an UPDATE. So after I have
> successfully searched for a record with @cnum, do I need to get the
> value of the customernum text box again for the UPDATE query or do I
> use the value of @cnum from the SELECT query?
>
> Please feel free to ask if any of my questions here are confusing.
>
> If anybody could clarify this for me, I would really appreciate it.
>
> Thanks in advance.
>
> On Mar 17, 7:10 am, The_Fruitman <evilfruitsmas...@gmail.com> wrote:
>
>
>
> > You can choose to use either option that you have listed.
>
> > A little internet searching goes a long way to solve your problem.
>
> >http://www.google.com/search?hl=en&q=update+command+in+sql&aq=0&oq=Up...
>
> > First item on the 
> > list:http://www.comptechdoc.org/independent/database/begin/sqlupdate.html
>
> >http://www.google.com/search?hl=en&q=update+database+with+tableadapter
>
> > First item on the 
> > list:http://msdn.microsoft.com/en-us/library/ms233819(VS.80).aspx
>
> >http://www.google.com/search?hl=en&q=update+database+from+dataset&aq=...
>
> > First item on the 
> > listhttp://quickstart.developerfusion.co.uk/quickstart/howto/doc/adoplus/...
>
> > On Mar 16, 2:16 pm, new db dvlpr <aronb2...@gmail.com> wrote:
>
> > > Hello all,
>
> > > I have a general question. I am trying to figure out how to do a
> > > update from a visual basic 2005 to a SQL server 2005 database.
> > > Currently, I have the application connecting and retrieving data from
> > > the database. But I can't seem to figure out how to do an update. I
> > > will explain what I am trying to do. As an example, a user searches
> > > for a certain customer and then upon finding some info for that
> > > customer, user wants to update / enter some new info about customer
> > > by  providing input into certain form controls (textboxes, comboboxes
> > > etc). After user has finished entering the info and then clicks the
> > > 'Save' button, those values should be passed back into the database
> > > and from there to the actual database.
>
> > > I think this can be done through two similar ways. One way is to
> > > create an Update query under the appropriate table adapter in designer
> > > mode of the dataset and then in the vb form code, pass the appropriate
> > > values to the query. However, I am not sure what this query in the
> > > tableadapter should look like and how to pass the values to it.
>
> > > The other way to do this task I think is by declaring and setting the
> > > appropriate sql connection string, the dataadapter, sql query as the
> > > sql command text, the dataset in the form's vb code.
>
> > > One important thing to note is that I don't want to do this task
> > > through a toolstrip and the automatically created save button on
> > > there. I am using a regular vb button to initiate the event to update.
>
> > > Thanks in advance.- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Reply via email to