473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Adding data to table

Hey,

I am trying to do this tutorial on the microsoft site :
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dndotnet/html/usingadonet.asp

I can get everything to work up to the DataAdd part
(Section heading is Adding Rows to a DataSet)

I dont really know what to do after i have added all the
code for the DataAdd() procedure. Other than the DataAdd
() for the button that i want it to use.

I dont know where to put that INSERT SQL Statement or add
the new row to the datatable in the dataset.

Also in that main code of the DataAdd() procedure there
is a line like this:

oBuild = New SqlClient.SqlDataAdapter(oAdapter)

Does anyone know why i get : Value of
type 'System.Data.SqlClient.SqlDataAdapter' cannot be
converted to 'System.Data.SqlClient.SqlCommand'.

???
Any help on this would be much appreciated.

Thank you.

Nov 20 '05 #1
10 2304
the error is b/c oBuild is of a different and incompatible type than a
sqldataadapter. it is a sqlcommand object. it's like saying "this is an
apple...make it into an orange."

steve
"Trevor" <tj**@bigpond.net.au> wrote in message
news:06****************************@phx.gbl...
Hey,

I am trying to do this tutorial on the microsoft site :
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dndotnet/html/usingadonet.asp

I can get everything to work up to the DataAdd part
(Section heading is Adding Rows to a DataSet)

I dont really know what to do after i have added all the
code for the DataAdd() procedure. Other than the DataAdd
() for the button that i want it to use.

I dont know where to put that INSERT SQL Statement or add
the new row to the datatable in the dataset.

Also in that main code of the DataAdd() procedure there
is a line like this:

oBuild = New SqlClient.SqlDataAdapter(oAdapter)

Does anyone know why i get : Value of
type 'System.Data.SqlClient.SqlDataAdapter' cannot be
converted to 'System.Data.SqlClient.SqlCommand'.

???
Any help on this would be much appreciated.

Thank you.

Nov 20 '05 #2
Ok so what do i do?

What do i use instead?

The code is microsofts.
-----Original Message-----
the error is b/c oBuild is of a different and incompatible type than asqldataadapter. it is a sqlcommand object. it's like saying "this is anapple...make it into an orange."

steve
"Trevor" <tj**@bigpond.net.au> wrote in message
news:06****************************@phx.gbl...
Hey,

I am trying to do this tutorial on the microsoft site :
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dndotnet/html/usingadonet.asp

I can get everything to work up to the DataAdd part
(Section heading is Adding Rows to a DataSet)

I dont really know what to do after i have added all the code for the DataAdd() procedure. Other than the DataAdd () for the button that i want it to use.

I dont know where to put that INSERT SQL Statement or add the new row to the datatable in the dataset.

Also in that main code of the DataAdd() procedure there
is a line like this:

oBuild = New SqlClient.SqlDataAdapter(oAdapter)

Does anyone know why i get : Value of
type 'System.Data.SqlClient.SqlDataAdapter' cannot be
converted to 'System.Data.SqlClient.SqlCommand'.

???
Any help on this would be much appreciated.

Thank you.

.

Nov 20 '05 #3
Please post your code as you have it.

"Trevor" <tj**@bigpond.net.au> wrote in message
news:0c****************************@phx.gbl...
Ok so what do i do?

What do i use instead?

The code is microsofts.
-----Original Message-----
the error is b/c oBuild is of a different and

incompatible type than a
sqldataadapter. it is a sqlcommand object. it's like

saying "this is an
apple...make it into an orange."

steve
"Trevor" <tj**@bigpond.net.au> wrote in message
news:06****************************@phx.gbl...
Hey,

I am trying to do this tutorial on the microsoft site :
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dndotnet/html/usingadonet.asp

I can get everything to work up to the DataAdd part
(Section heading is Adding Rows to a DataSet)

I dont really know what to do after i have added all the code for the DataAdd() procedure. Other than the DataAdd () for the button that i want it to use.

I dont know where to put that INSERT SQL Statement or add the new row to the datatable in the dataset.

Also in that main code of the DataAdd() procedure there
is a line like this:

oBuild = New SqlClient.SqlDataAdapter(oAdapter)

Does anyone know why i get : Value of
type 'System.Data.SqlClient.SqlDataAdapter' cannot be
converted to 'System.Data.SqlClient.SqlCommand'.

???
Any help on this would be much appreciated.

Thank you.

.

Nov 20 '05 #4
i don't know if i've the time to look at the site's example but i may.

as far as it being from microsoft...most people would scoff and say that
that's just ms. most of the coding examples are snippets of example
projects. the code is either wrong, or they didn't fully explain it, or
omitted the inclusion of other pertanent information...that's what i'll say
about it.

steve
"Trevor" <tj**@bigpond.net.au> wrote in message
news:0c****************************@phx.gbl...
Ok so what do i do?

What do i use instead?

The code is microsofts.
-----Original Message-----
the error is b/c oBuild is of a different and

incompatible type than a
sqldataadapter. it is a sqlcommand object. it's like

saying "this is an
apple...make it into an orange."

steve
"Trevor" <tj**@bigpond.net.au> wrote in message
news:06****************************@phx.gbl...
Hey,

I am trying to do this tutorial on the microsoft site :
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dndotnet/html/usingadonet.asp

I can get everything to work up to the DataAdd part
(Section heading is Adding Rows to a DataSet)

I dont really know what to do after i have added all the code for the DataAdd() procedure. Other than the DataAdd () for the button that i want it to use.

I dont know where to put that INSERT SQL Statement or add the new row to the datatable in the dataset.

Also in that main code of the DataAdd() procedure there
is a line like this:

oBuild = New SqlClient.SqlDataAdapter(oAdapter)

Does anyone know why i get : Value of
type 'System.Data.SqlClient.SqlDataAdapter' cannot be
converted to 'System.Data.SqlClient.SqlCommand'.

???
Any help on this would be much appreciated.

Thank you.

.

Nov 20 '05 #5
The code is the same as it is on the website that i
stated. I have pasted it below anyway

The code for the DataUpdate() works just fine.

Also there is the part on that website for the INSERT SQL
statement. Do i need to put that in or does that code i
just created with the DataAdd() do all that for me?

If so where do i put it?

Here is what i have anyway:

Private Sub DataAdd()
Dim oAdapter As SqlClient.SqlDataAdapter
Dim oBuild As SqlClient.SqlCommandBuilder
Dim oDR As DataRow
Dim strSQL As String
Dim strConn As String

' Create New DataRow Object From DataSet
oDR = moDS.Tables("Products").NewRow()
oDR.BeginEdit()

' Load new data into row
oDR("ProductName") = txtName.Text
oDR("SupplierID") = CType
(cboSupplier.SelectedItem, _
PDSAListItemNumeric).ID
oDR("CategoryID") = CType
(cboCategory.SelectedItem, _
PDSAListItemNumeric).ID
oDR("QuantityPerUnit") = cboSupplier.Text
oDR("UnitPrice") = CDec(txtPrice.Text)
oDR("UnitsInStock") = CShort(txtInStock.Text)
oDR("UnitsOnOrder") = CShort(txtOnOrder.Text)
oDR("ReorderLevel") = CShort(txtReorder.Text)
oDR("Discontinued") = CBool(chkDisc.Checked)

' Tell DataRow you are done adding data
oDR.EndEdit()
' Add DataRow to DataSet
moDS.Tables("Products").Rows.Add(oDR)

Try
' Get Connection String
strConn = ConnectStringBuild()
' Build SQL String
strSQL = "SELECT * FROM Products "
' Create New DataAdapter
oAdapter = _
New SqlClient.SqlDataAdapter(strSQL, strConn)
' Create CommandBuilder for Adapter
' This will build INSERT, UPDATE and DELETE
SQL
oBuild = New SqlClient.SqlDataAdapter
(oAdapter)

' Get Insert Command Object
oAdapter.InsertCommand =
oBuild.GetInsertCommand()

' Submit INSERT statement through Adapter
oAdapter.Update(moDS, "Products")
' Tell DataSet changes to data source are
complete
moDS.AcceptChanges()

' Reload the list box
ListLoad()

Catch oException As Exception
MessageBox.Show(oException.Message)

End Try
End Sub

-----Original Message-----
Please post your code as you have it.

"Trevor" <tj**@bigpond.net.au> wrote in message
news:0c****************************@phx.gbl...
Ok so what do i do?

What do i use instead?

The code is microsofts.
>-----Original Message-----
>the error is b/c oBuild is of a different and

incompatible type than a
>sqldataadapter. it is a sqlcommand object. it's like

saying "this is an
>apple...make it into an orange."
>
>steve
>
>
>"Trevor" <tj**@bigpond.net.au> wrote in message
>news:06****************************@phx.gbl...
>> Hey,
>>
>> I am trying to do this tutorial on the microsoft site : >> http://msdn.microsoft.com/library/default.asp?
>> url=/library/en-us/dndotnet/html/usingadonet.asp
>>
>> I can get everything to work up to the DataAdd part
>> (Section heading is Adding Rows to a DataSet)
>>
>> I dont really know what to do after i have added all

the
>> code for the DataAdd() procedure. Other than the

DataAdd
>> () for the button that i want it to use.
>>
>> I dont know where to put that INSERT SQL Statement or
add
>> the new row to the datatable in the dataset.
>>
>> Also in that main code of the DataAdd() procedure

there >> is a line like this:
>>
>> oBuild = New SqlClient.SqlDataAdapter(oAdapter)
>>
>> Does anyone know why i get : Value of
>> type 'System.Data.SqlClient.SqlDataAdapter' cannot be >> converted to 'System.Data.SqlClient.SqlCommand'.
>>
>> ???
>>
>>
>> Any help on this would be much appreciated.
>>
>> Thank you.
>>
>
>
>.
>

.

Nov 20 '05 #6
Yeh i know its typical of microsoft, but i just want to
know how i can get around it so i can add data to the sql
database.

Thanks
-----Original Message-----
i don't know if i've the time to look at the site's example but i may.
as far as it being from microsoft...most people would scoff and say thatthat's just ms. most of the coding examples are snippets of exampleprojects. the code is either wrong, or they didn't fully explain it, oromitted the inclusion of other pertanent information...that's what i'll sayabout it.

steve
"Trevor" <tj**@bigpond.net.au> wrote in message
news:0c****************************@phx.gbl...
Ok so what do i do?

What do i use instead?

The code is microsofts.
>-----Original Message-----
>the error is b/c oBuild is of a different and

incompatible type than a
>sqldataadapter. it is a sqlcommand object. it's like

saying "this is an
>apple...make it into an orange."
>
>steve
>
>
>"Trevor" <tj**@bigpond.net.au> wrote in message
>news:06****************************@phx.gbl...
>> Hey,
>>
>> I am trying to do this tutorial on the microsoft site : >> http://msdn.microsoft.com/library/default.asp?
>> url=/library/en-us/dndotnet/html/usingadonet.asp
>>
>> I can get everything to work up to the DataAdd part
>> (Section heading is Adding Rows to a DataSet)
>>
>> I dont really know what to do after i have added all

the
>> code for the DataAdd() procedure. Other than the

DataAdd
>> () for the button that i want it to use.
>>
>> I dont know where to put that INSERT SQL Statement or
add
>> the new row to the datatable in the dataset.
>>
>> Also in that main code of the DataAdd() procedure

there >> is a line like this:
>>
>> oBuild = New SqlClient.SqlDataAdapter(oAdapter)
>>
>> Does anyone know why i get : Value of
>> type 'System.Data.SqlClient.SqlDataAdapter' cannot be >> converted to 'System.Data.SqlClient.SqlCommand'.
>>
>> ???
>>
>>
>> Any help on this would be much appreciated.
>>
>> Thank you.
>>
>
>
>.
>

.

Nov 20 '05 #7
let's digress...can you describe a scenario where you need data interaction?
i can either pull some existing code (that i *know* works) or come up w/
some in a snap.

steve

"Trevor" <tj**@bigpond.net.au> wrote in message
news:04****************************@phx.gbl...
Yeh i know its typical of microsoft, but i just want to
know how i can get around it so i can add data to the sql
database.

Thanks
-----Original Message-----
i don't know if i've the time to look at the site's

example but i may.

as far as it being from microsoft...most people would

scoff and say that
that's just ms. most of the coding examples are snippets

of example
projects. the code is either wrong, or they didn't fully

explain it, or
omitted the inclusion of other pertanent

information...that's what i'll say
about it.

steve
"Trevor" <tj**@bigpond.net.au> wrote in message
news:0c****************************@phx.gbl...
Ok so what do i do?

What do i use instead?

The code is microsofts.

>-----Original Message-----
>the error is b/c oBuild is of a different and
incompatible type than a
>sqldataadapter. it is a sqlcommand object. it's like
saying "this is an
>apple...make it into an orange."
>
>steve
>
>
>"Trevor" <tj**@bigpond.net.au> wrote in message
>news:06****************************@phx.gbl...
>> Hey,
>>
>> I am trying to do this tutorial on the microsoft site : >> http://msdn.microsoft.com/library/default.asp?
>> url=/library/en-us/dndotnet/html/usingadonet.asp
>>
>> I can get everything to work up to the DataAdd part
>> (Section heading is Adding Rows to a DataSet)
>>
>> I dont really know what to do after i have added all
the
>> code for the DataAdd() procedure. Other than the
DataAdd
>> () for the button that i want it to use.
>>
>> I dont know where to put that INSERT SQL Statement or add
>> the new row to the datatable in the dataset.
>>
>> Also in that main code of the DataAdd() procedure there >> is a line like this:
>>
>> oBuild = New SqlClient.SqlDataAdapter(oAdapter)
>>
>> Does anyone know why i get : Value of
>> type 'System.Data.SqlClient.SqlDataAdapter' cannot be >> converted to 'System.Data.SqlClient.SqlCommand'.
>>
>> ???
>>
>>
>> Any help on this would be much appreciated.
>>
>> Thank you.
>>
>
>
>.
>

.

Nov 20 '05 #8
Hey,

I think i have just fixed half of the problem.

the code was: oBuild = New SqlClient.SqlDataAdapter
(oAdapter)

So i changed it to the obvious (same as the update):
oBuild = New SqlClient.SqlCommandBuilder(oAdapter)

hehe silly me i should have picked that up.

But i still have one problem.

I still have not done all of the stuff that is required
to the DataAdd() procedure. i think i need to do this (as
it says on the site):

To add a new record to the table in the database, you
first need to add a new row to the DataTable in the
DataSet. You can do this by using the NewRow method to
create a new DataRow. Invoke the BeginEdit method on this
new DataRow so that you can place data into the
appropriate columns. When you have updated all of the
columns, invoke the EndEdit method. Add this new DataRow
to the DataTable in the DataSet by passing the DataRow to
the Add method of the Rows collection in the DataTable.

Use a Command Builder Object to Create SQL
Now that the data is in the DataSet, you can build a
DataAdapter to submit this new data to the database.
Create the DataAdapter by passing in the same SQL
statement that you used to load the DataSet and a
connection string. You then pass the DataAdapter object
to the constructor of the CommandBuilder class and it
creates a new Builder object for you. The
GetInsertCommand method can then be called on this
CommandBuilder object to retrieve a command object that
contains an INSERT statement for this table. The INSERT
statement uses question marks as placeholders for each
piece of data in the DataSet.

When using the SqlCommandBuilder, the INSERT statement
will look something like this:

INSERT
INTO "Products"( "ProductName" , "SupplierID" , "CategoryI
D" ,
"QuantityPerUnit" , "UnitPrice" , "UnitsInStock" , "UnitsO
nOrder" ,
"ReorderLevel" , "Discontinued" ) VALUES ( @ProductName ,
@SupplierID ,
@CategoryID , @QuantityPerUnit , @UnitPrice ,
@UnitsInStock ,
@UnitsOnOrder , @Reorderlevel , @Discontinued )
When using the OleDbCommandBuilder the INSERT statement
will look something like this:

INSERT
INTO "Products"( "ProductName" , "SupplierID" , "CategoryI
D" ,
"QuantityPerUnit" , "UnitPrice" , "UnitsInStock" , "UnitsO
nOrder" ,
"ReorderLevel" , "Discontinued" ) VALUES
( ? , ? , ? , ? , ? , ? , ? , ?
, ? )
Each parameter marker in the statement ("@<columnname>"
for the SqlCommand and "?" for the OleDbCommand)
represents where the data from the DataSet will be placed
when you submit this INSERT statement through the
DataAdapter. This replacement is done automatically by
the DataAdapter and requires no extra programming on your
part. You tell the DataAdapter to submit this INSERT
statement by passing in the DataSet object and the name
of the table in the DataSet that is to be updated to the
Update method of the DataAdapter. After this Update
method is completed, invoke the AcceptChanges method on
the DataSet. This informs the new DataRow that it has
been updated in the database.

-----Original Message-----
The code is the same as it is on the website that i
stated. I have pasted it below anyway

The code for the DataUpdate() works just fine.

Also there is the part on that website for the INSERT SQLstatement. Do i need to put that in or does that code i
just created with the DataAdd() do all that for me?

If so where do i put it?

Here is what i have anyway:

Private Sub DataAdd()
Dim oAdapter As SqlClient.SqlDataAdapter
Dim oBuild As SqlClient.SqlCommandBuilder
Dim oDR As DataRow
Dim strSQL As String
Dim strConn As String

' Create New DataRow Object From DataSet
oDR = moDS.Tables("Products").NewRow()
oDR.BeginEdit()

' Load new data into row
oDR("ProductName") = txtName.Text
oDR("SupplierID") = CType
(cboSupplier.SelectedItem, _
PDSAListItemNumeric).ID
oDR("CategoryID") = CType
(cboCategory.SelectedItem, _
PDSAListItemNumeric).ID
oDR("QuantityPerUnit") = cboSupplier.Text
oDR("UnitPrice") = CDec(txtPrice.Text)
oDR("UnitsInStock") = CShort(txtInStock.Text)
oDR("UnitsOnOrder") = CShort(txtOnOrder.Text)
oDR("ReorderLevel") = CShort(txtReorder.Text)
oDR("Discontinued") = CBool(chkDisc.Checked)

' Tell DataRow you are done adding data
oDR.EndEdit()
' Add DataRow to DataSet
moDS.Tables("Products").Rows.Add(oDR)

Try
' Get Connection String
strConn = ConnectStringBuild()
' Build SQL String
strSQL = "SELECT * FROM Products "
' Create New DataAdapter
oAdapter = _
New SqlClient.SqlDataAdapter(strSQL, strConn) ' Create CommandBuilder for Adapter
' This will build INSERT, UPDATE and DELETE
SQL
oBuild = New SqlClient.SqlDataAdapter
(oAdapter)

' Get Insert Command Object
oAdapter.InsertCommand =
oBuild.GetInsertCommand()

' Submit INSERT statement through Adapter
oAdapter.Update(moDS, "Products")
' Tell DataSet changes to data source are
complete
moDS.AcceptChanges()

' Reload the list box
ListLoad()

Catch oException As Exception
MessageBox.Show(oException.Message)

End Try
End Sub

-----Original Message-----
Please post your code as you have it.

"Trevor" <tj**@bigpond.net.au> wrote in message
news:0c****************************@phx.gbl...
Ok so what do i do?

What do i use instead?

The code is microsofts.

>-----Original Message-----
>the error is b/c oBuild is of a different and
incompatible type than a
>sqldataadapter. it is a sqlcommand object. it's like
saying "this is an
>apple...make it into an orange."
>
>steve
>
>
>"Trevor" <tj**@bigpond.net.au> wrote in message
>news:06****************************@phx.gbl...
>> Hey,
>>
>> I am trying to do this tutorial on the microsoftsite : >> http://msdn.microsoft.com/library/default.asp?
>> url=/library/en-us/dndotnet/html/usingadonet.asp
>>
>> I can get everything to work up to the DataAdd part
>> (Section heading is Adding Rows to a DataSet)
>>
>> I dont really know what to do after i have added all the
>> code for the DataAdd() procedure. Other than the
DataAdd
>> () for the button that i want it to use.
>>
>> I dont know where to put that INSERT SQL Statementor add
>> the new row to the datatable in the dataset.
>>
>> Also in that main code of the DataAdd() procedurethere >> is a line like this:
>>
>> oBuild = New SqlClient.SqlDataAdapter(oAdapter)
>>
>> Does anyone know why i get : Value of
>> type 'System.Data.SqlClient.SqlDataAdapter' cannotbe >> converted to 'System.Data.SqlClient.SqlCommand'.
>>
>> ???
>>
>>
>> Any help on this would be much appreciated.
>>
>> Thank you.
>>
>
>
>.
>

.

.

Nov 20 '05 #9
I should probably say that i dont have any idea how to do
that, they explain everything else great except or that
part.

Where and how do i put all that?
-----Original Message-----
Hey,

I think i have just fixed half of the problem.

the code was: oBuild = New SqlClient.SqlDataAdapter
(oAdapter)

So i changed it to the obvious (same as the update):
oBuild = New SqlClient.SqlCommandBuilder(oAdapter)

hehe silly me i should have picked that up.

But i still have one problem.

I still have not done all of the stuff that is required
to the DataAdd() procedure. i think i need to do this (asit says on the site):

To add a new record to the table in the database, you
first need to add a new row to the DataTable in the
DataSet. You can do this by using the NewRow method to
create a new DataRow. Invoke the BeginEdit method on thisnew DataRow so that you can place data into the
appropriate columns. When you have updated all of the
columns, invoke the EndEdit method. Add this new DataRow
to the DataTable in the DataSet by passing the DataRow tothe Add method of the Rows collection in the DataTable.

Use a Command Builder Object to Create SQL
Now that the data is in the DataSet, you can build a
DataAdapter to submit this new data to the database.
Create the DataAdapter by passing in the same SQL
statement that you used to load the DataSet and a
connection string. You then pass the DataAdapter object
to the constructor of the CommandBuilder class and it
creates a new Builder object for you. The
GetInsertCommand method can then be called on this
CommandBuilder object to retrieve a command object that
contains an INSERT statement for this table. The INSERT
statement uses question marks as placeholders for each
piece of data in the DataSet.

When using the SqlCommandBuilder, the INSERT statement
will look something like this:

INSERT
INTO "Products"( "ProductName" , "SupplierID" , "Category ID" ,
"QuantityPerUnit" , "UnitPrice" , "UnitsInStock" , "Units OnOrder" ,
"ReorderLevel" , "Discontinued" ) VALUES ( @ProductName ,@SupplierID ,
@CategoryID , @QuantityPerUnit , @UnitPrice ,
@UnitsInStock ,
@UnitsOnOrder , @Reorderlevel , @Discontinued )
When using the OleDbCommandBuilder the INSERT statement
will look something like this:

INSERT
INTO "Products"( "ProductName" , "SupplierID" , "Category ID" ,
"QuantityPerUnit" , "UnitPrice" , "UnitsInStock" , "Units OnOrder" ,
"ReorderLevel" , "Discontinued" ) VALUES
( ? , ? , ? , ? , ? , ? , ? , ?
, ? )
Each parameter marker in the statement ("@<columnname>"
for the SqlCommand and "?" for the OleDbCommand)
represents where the data from the DataSet will be placedwhen you submit this INSERT statement through the
DataAdapter. This replacement is done automatically by
the DataAdapter and requires no extra programming on yourpart. You tell the DataAdapter to submit this INSERT
statement by passing in the DataSet object and the name
of the table in the DataSet that is to be updated to the
Update method of the DataAdapter. After this Update
method is completed, invoke the AcceptChanges method on
the DataSet. This informs the new DataRow that it has
been updated in the database.

-----Original Message-----
The code is the same as it is on the website that i
stated. I have pasted it below anyway

The code for the DataUpdate() works just fine.

Also there is the part on that website for the INSERT

SQL
statement. Do i need to put that in or does that code i
just created with the DataAdd() do all that for me?

If so where do i put it?

Here is what i have anyway:

Private Sub DataAdd()
Dim oAdapter As SqlClient.SqlDataAdapter
Dim oBuild As SqlClient.SqlCommandBuilder
Dim oDR As DataRow
Dim strSQL As String
Dim strConn As String

' Create New DataRow Object From DataSet
oDR = moDS.Tables("Products").NewRow()
oDR.BeginEdit()

' Load new data into row
oDR("ProductName") = txtName.Text
oDR("SupplierID") = CType
(cboSupplier.SelectedItem, _
PDSAListItemNumeric).ID
oDR("CategoryID") = CType
(cboCategory.SelectedItem, _
PDSAListItemNumeric).ID
oDR("QuantityPerUnit") = cboSupplier.Text
oDR("UnitPrice") = CDec(txtPrice.Text)
oDR("UnitsInStock") = CShort(txtInStock.Text)
oDR("UnitsOnOrder") = CShort(txtOnOrder.Text)
oDR("ReorderLevel") = CShort(txtReorder.Text)
oDR("Discontinued") = CBool(chkDisc.Checked)

' Tell DataRow you are done adding data
oDR.EndEdit()
' Add DataRow to DataSet
moDS.Tables("Products").Rows.Add(oDR)

Try
' Get Connection String
strConn = ConnectStringBuild()
' Build SQL String
strSQL = "SELECT * FROM Products "
' Create New DataAdapter
oAdapter = _
New SqlClient.SqlDataAdapter(strSQL,

strConn)
' Create CommandBuilder for Adapter
' This will build INSERT, UPDATE and DELETE
SQL
oBuild = New SqlClient.SqlDataAdapter
(oAdapter)

' Get Insert Command Object
oAdapter.InsertCommand =
oBuild.GetInsertCommand()

' Submit INSERT statement through Adapter
oAdapter.Update(moDS, "Products")
' Tell DataSet changes to data source are
complete
moDS.AcceptChanges()

' Reload the list box
ListLoad()

Catch oException As Exception
MessageBox.Show(oException.Message)

End Try
End Sub

-----Original Message-----
Please post your code as you have it.

"Trevor" <tj**@bigpond.net.au> wrote in message
news:0c****************************@phx.gbl.. .
Ok so what do i do?

What do i use instead?

The code is microsofts.

>-----Original Message-----
>the error is b/c oBuild is of a different and
incompatible type than a
>sqldataadapter. it is a sqlcommand object. it's like
saying "this is an
>apple...make it into an orange."
>
>steve
>
>
>"Trevor" <tj**@bigpond.net.au> wrote in message
>news:06****************************@phx.gbl...
>> Hey,
>>
>> I am trying to do this tutorial on the microsoft

site :
>> http://msdn.microsoft.com/library/default.asp?
>> url=/library/en-us/dndotnet/html/usingadonet.asp
>>
>> I can get everything to work up to the DataAdd part >> (Section heading is Adding Rows to a DataSet)
>>
>> I dont really know what to do after i have addedall the
>> code for the DataAdd() procedure. Other than the
DataAdd
>> () for the button that i want it to use.
>>
>> I dont know where to put that INSERT SQL
Statementor
add
>> the new row to the datatable in the dataset.
>>
>> Also in that main code of the DataAdd() procedure

there
>> is a line like this:
>>
>> oBuild = New SqlClient.SqlDataAdapter(oAdapter)
>>
>> Does anyone know why i get : Value of
>> type 'System.Data.SqlClient.SqlDataAdapter'
cannotbe
>> converted to 'System.Data.SqlClient.SqlCommand'.
>>
>> ???
>>
>>
>> Any help on this would be much appreciated.
>>
>> Thank you.
>>
>
>
>.
>
.

.

.

Nov 20 '05 #10
Ok,

I have put in the DataAdd() part and it loads fine (i
have now fixed the problem with the so the code is ok,
but i think i need to put in more code to add a row into
the table before i can write to it (as the tutorial says
on that site). The reason i figure this is when i press
the add button i get this error....
An unhandled exception of
type 'System.Data.NoNullAllowedException' occurred in
system.data.dll

Additional information: Column 'ProductID' does not allow
nulls.
-----Original Message-----
let's digress...can you describe a scenario where you need data interaction?i can either pull some existing code (that i *know* works) or come up w/some in a snap.

steve

"Trevor" <tj**@bigpond.net.au> wrote in message
news:04****************************@phx.gbl...
Yeh i know its typical of microsoft, but i just want to
know how i can get around it so i can add data to the sql database.

Thanks
>-----Original Message-----
>i don't know if i've the time to look at the site's

example but i may.
>
>as far as it being from microsoft...most people would

scoff and say that
>that's just ms. most of the coding examples are snippets
of example
>projects. the code is either wrong, or they didn't
fully explain it, or
>omitted the inclusion of other pertanent

information...that's what i'll say
>about it.
>
>steve
>
>
>"Trevor" <tj**@bigpond.net.au> wrote in message
>news:0c****************************@phx.gbl...
>> Ok so what do i do?
>>
>> What do i use instead?
>>
>> The code is microsofts.
>>
>> >-----Original Message-----
>> >the error is b/c oBuild is of a different and
>> incompatible type than a
>> >sqldataadapter. it is a sqlcommand object. it's
like >> saying "this is an
>> >apple...make it into an orange."
>> >
>> >steve
>> >
>> >
>> >"Trevor" <tj**@bigpond.net.au> wrote in message
>> >news:06****************************@phx.gbl...
>> >> Hey,
>> >>
>> >> I am trying to do this tutorial on the microsoft

site :
>> >> http://msdn.microsoft.com/library/default.asp?
>> >> url=/library/en-us/dndotnet/html/usingadonet.asp
>> >>
>> >> I can get everything to work up to the DataAdd part >> >> (Section heading is Adding Rows to a DataSet)
>> >>
>> >> I dont really know what to do after i have added all >> the
>> >> code for the DataAdd() procedure. Other than the
>> DataAdd
>> >> () for the button that i want it to use.
>> >>
>> >> I dont know where to put that INSERT SQL

Statement or
>> add
>> >> the new row to the datatable in the dataset.
>> >>
>> >> Also in that main code of the DataAdd() procedure

there
>> >> is a line like this:
>> >>
>> >> oBuild = New SqlClient.SqlDataAdapter(oAdapter)
>> >>
>> >> Does anyone know why i get : Value of
>> >> type 'System.Data.SqlClient.SqlDataAdapter'
cannot be
>> >> converted to 'System.Data.SqlClient.SqlCommand'.
>> >>
>> >> ???
>> >>
>> >>
>> >> Any help on this would be much appreciated.
>> >>
>> >> Thank you.
>> >>
>> >
>> >
>> >.
>> >
>
>
>.
>

.

Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul | last post by:
Hi I have a table that currently has 466 columns and about 700,000 records. Adding a new DEFAULT column to this table takes a long time. It it a lot faster to recreate the table with the new...
2
by: Chris Cobb | last post by:
I have a table that currently contains 718000 rows. I wish to add a column to the table. Adding this column anywhere other than the end of the table requires exporting data, a drop and recreate,...
3
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding 2-3 new columns worth. Now my questions are:...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
3
by: Tyler Carver | last post by:
I am trying to use some dynamic controls that are built and then added to tables. The problem that I am having is the timing of when I can populate the controls and have the state remain after a...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
2
by: Steve | last post by:
I have zero experience with ODBC. If I have an Access frontend connected to a SQL Database using ODBC, are the tables connected like a frontend/backend Access database where the the tables you see...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.