autosave in datagrid.

  • Thread starter Thread starter jaYPee
  • Start date Start date
J

jaYPee

I am using dataset as a datasource for my datagrid. I'm wondering how
to program to autosave the changes made in a datagrid just like
microsoft access.

any help is greatly appreciated.
 
Hi JaYpee,

Can you tell us what you did till now to do that?
Otherwise maybe our startpoint is to far back.

(Did you already made a dataadapter.update by instance?)

Cor
 
Hi JaYpee,

Can you tell us what you did till now to do that?
Otherwise maybe our startpoint is to far back.

(Did you already made a dataadapter.update by instance?)

Cor
i am not too very familiar w/ different kinds of connection but i
think what u said is came from the wizard. like
OleDbDataAdapter1.Update(DsAuthors1) or an sql adapter. the source i
am working on is a hard coded source code from 101 example as i have
mentioned from my previous post.

by d way sorry for replying w/ a different thread.

the code from the sample looks something like this. this is my source
code now that come from the sample.

Dim scnnNW As New SqlConnection(strConn)

Dim strSQL As String = _
"SELECT IDNo, LastName, FirstName " & _
"FROM Students"

' A SqlCommand object is used to execute the SQL
commands.
Dim scmd As New SqlCommand(strSQL, scnnNW)

' A SqlDataAdapter uses the SqlCommand object to fill
a DataSet.
sda = New SqlDataAdapter(scmd)

' A SqlCommandBuilder automatically generates the SQL
commands needed
' to update the database later (in the btnSave_Click
event handler).
Dim scb As New SqlCommandBuilder(sda)

' The commands generated by the SqlCommandBuilder are
based on the
' currently set CommandText of the SqlCommand object.
As this will
' be changing to a SQL statement that won't be needed
for an Update
' in the btnSave Click event handler, you can call
GetUpdateCommand
' explicitly to generate the Update command based on
the current
' CommandText property value.
scb.GetUpdateCommand()

' Create a new DataSet and fill its first DataTable.
dsStudentCourse = New DataSet()
sda.Fill(dsStudentCourse, "Students")

' Reset the CommandText to get the Employee orders.
scmd.CommandText = _
"SELECT SchYrSemID, IDNo, SchYr, Sem FROM
SchYrSem"

' Fill the second table in the DataSet.
sda.Fill(dsStudentCourse, "SchYrSem")

' Reset the CommandText to get the Order details.
scmd.CommandText = _
"SELECT SchYrSemCourseID, SchYrSemID,
Course.CourseID, CourseTitle, CourseDesc, Unit, [Hours/Week] FROM
Course INNER JOIN SchYrSemCourseJoin ON Course.CourseID =
SchYrSemCourseJoin.CourseID"

' Fill the fourth table in the DataSet.
sda.Fill(dsStudentCourse, "SchYrSemCourseJoin")

and i don't know how can i update the datagrid now.

thanks if u can help me w/ this problem.
 
Hi jaYPee,

To update a dataset you have to use a SQLdataadapter or OLeDBdataadapter

Basicly you wrote it already,
SQLdatatadapter.update(ds)

It is confusing if you use samples which are made by the designer or all by
hand.

But have a look to the dataadaper, and keep in mind reading the
documentation, that there is a lot of difference when all is made by the
designer or by hand but you can not recognize that direct in the samples.
(The sample you are using is not using the designer as far as I know).

It is a lot of work for the first time to use that sample to do what you
ask, I think it is better to make some code yourself looking at that sample,
by instance

That has one datagrid,
That has one database (employees from northwind is nice for that)
That has one button

In the load event of the form you read it using the datadatper.fill.
In the button click event you write it back using the dataadapter.update

If you have made that and you have problems, tell the problems than we can
help you further I think.

Success,

I hope this did help a little bit?

Cor
 
thanks u very much for the support. i have found out that when i
update the dataset it gives me an error telling "dynamic sql
generation is not supported against multiple base tables". since the
dataset contains 4 table so may be this is what the error come from.

by d way i try to use the sample from 101 samples because i want to
have a form like that. it contains a parent form and a two child form.
just like what we can see in the sample database of microsoft access
97 entitled video collection wizard. i don't have any problem creating
this kind of database using microsoft access but i want to migrate to
vb .net and i have trouble learning this new language.

i am very thankful if u can point me to any sample program that
resembles from the sample made by microsoft (ie the 101 sample app)

thanks once again.
 
Hi jaYpee,

When I did know that I had not written so much.

I never saw a complete sample like this with an dataadapte.update from
Microsoft, but there is on MSDN enough in snippets.

Therefore is to make that sample yourself as I told less work than
searching for a existing, because when you start with it and look at your
existing you will see you only have to write normaly less than 30 lines of
code

I hope this helps,

Cor
 
thanks but i can't find in msdn on how to update the dataset that has
multiple table.
 
Back
Top