how to insert record from another table to dataset?

A

Armin Zingler

jaYPee said:
as of now i am using a stored procedure from my sql server 2000 to
insert record from another table. what i need now is on how can i
insert record by not using the stored procedure and insert it
using dataset.
[...]
INSERT INTO SchYrSemCourseJoin ( CourseID, SchYrSemID )
SELECT CourseID, @SchYrSemID
FROM RegularLoad INNER JOIN [RegularLoad Details] ON
RegularLoad.RegularLoadID = [RegularLoad Details].RegularLoadID
WHERE ProgramID=@ProgramID AND Year=@Year AND Semester=@Sem;

IMO, a dataset doesn't make sense here. You don't want to load data into
memory, and that's where the dataset is used for. I think the SP is already
the best solution.
More ADO.Net: microsoft.public.dotnet.framework.adonet

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
J

jaYPee

as of now i am using a stored procedure from my sql server 2000 to
insert record from another table. what i need now is on how can i
insert record by not using the stored procedure and insert it using
dataset.

here is my code in stored procedure..

CREATE PROCEDURE AddRegularLoad

@SchYrSemID as int, @ProgramID as int, @Sem as varchar(50), @Year as
int

AS

BEGIN

SET NOCOUNT OFF

INSERT INTO SchYrSemCourseJoin ( CourseID, SchYrSemID )
SELECT CourseID, @SchYrSemID
FROM RegularLoad INNER JOIN [RegularLoad Details] ON
RegularLoad.RegularLoadID = [RegularLoad Details].RegularLoadID
WHERE ProgramID=@ProgramID AND Year=@Year AND Semester=@Sem;

END
GO
 
J

jaYPee

don't know wat u mean...this dataset is used to stored the data from
my table from my sql server 2000. am i right?
 
J

jaYPee

because when i used stored procedure it is automatically save the data
to another table. while if i don't used the stored procedure i have
the option if i want to save the data or not. by the way this data
will be inserted to the datagrid in my form
 
A

Armin Zingler

jaYPee said:
because when i used stored procedure it is automatically save the
data to another table. while if i don't used the stored procedure i
have the option if i want to save the data or not. by the way this
data will be inserted to the datagrid in my form

You did not mention what's your intention. Makes it hard to understand.

Yes, you can load the data in a dataset and bind it to a datagrid. Later you
can store the changes to the database. I'm not sure what's exactly your
problem. Here's the entry for using Datasets and data binding:

http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcreatingusingdatasets.asp
http://msdn.microsoft.com/library/en-us/vbcon/html/vboriDatasets.asp
http://msdn.microsoft.com/library/en-us/vbcon/html/vboriWindowsFormsDataArchitecture.asp

See also the already mentioned ADO.Net group for ADO.Net specific questions.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
C

Cor Ligthert

Hi jaYpee,

To give you Microsoft samples is difficult as I said because they all go not
farther than the fill, you seldom see them complete with the update.

Try to find this things
You need a connection (which you have already)
A dataadapter
A dataset.

The dataadapter is a class which does a lot for you.

When you use with that the
commandbuilder, than you are for the start very happy.

What you do
You make the connection.
You fill your dataset using the dataadapter
You bind that to your dagagrid (I asume all is windows forms)

The changes are done and you do
currencymanager.endcurrentedit (this is not the complete code)

Than you look if the dataset has changes
if dataset.haschanges
dataadapter.update(dataset)
end if

And all this you use in try and catch blocks.

Than your data handling is almost done.

I hope this helps someting?

Cor
 
J

jaYPee

my purpose is this. i have 2 datagrid in my form. the 2nd datagrid is
related to the 1st datagrid. now in my 1st datagrid there is a
checkbox that when i click that i want to fill the 2nd datagrid w/
records from another table. i have successfully done this in ms-access
and don't know how to do this w/ vb.net

anyway here's the code i used in ms-access when the value of checkbox
is equals to true.

DoCmd.RunSQL "INSERT INTO SchYrSemCourseJoin (
CourseID, SchYrSemID ) " _
& "SELECT [RegularLoad Details].CourseID, " &
Me!SchYrSemID & " " _
& "FROM RegularLoad INNER JOIN [RegularLoad
Details] " _
& "ON RegularLoad.RegularLoadID = [RegularLoad
Details].RegularLoadID " _
& "WHERE (((RegularLoad.ProgramID)= " &
Forms![Students]![ProgramID] & ") AND (RegularLoad.MajorID= " &
Me!MajorID & ") AND ((RegularLoad.Year)= " & Me!Year & ") AND " _
& "((RegularLoad.Semester)= '" & Me!Sem & "'));"

the table regular load and regular load details is related to each
other and is act as a template to the table schyrsemcoursejoin.

pls tell me if i did not explain better.

thanks for the help
 
C

Cor Ligthert

Hi jaYPee,

There are two methods (It is not standard) for using a combobox in a
datagrid.

The one is with a combobox and the otherone is with a comboboxcolumn, which
one are you using?

Although it is again a long time ago that I did look at that, so my help
will be probably very fair.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top