.Addnew only works the first time

Bigox

Member
Joined
Nov 19, 2005
Messages
8
Programming Experience
Beginner
Solved -- .Addnew only works the first time

SOLVED






I can post code if needed but its rather long,,,


anyhow, I am trying to update my orderline table one line at a time using the .addnew method.

the first insert works find, the second time I use the .addnew method it tells me that you cannot insert a null value into a field... my question is why is it saying that if there is no record being written,,, i am just doing the .addnew then later on it performs the update.

I guess it could be better explained by the code.

--------------------------------------------
'Add a new Rental Item
bmRentalItem.AddNew()
'Set proper controls before writing update
txtVideoIDITEM.Text = Integer.Parse(txtVideoID.Text)
txtRentalNOITEM.Text =
Integer.Parse(txtRentalNO.Text)
txtQty.Text =
Integer.Parse(txtQTYITEM.Text)
chkPurchaseDB.Checked = chkPurchase.Checked
'Write the update
bmRentalItem.EndCurrentEdit()
daRentalItem.Update(DsRentalItem1)
DsRentalItem1.AcceptChanges()

I know there may be more efficient ways of doing this and I am all ears, but right now this is the only way I can figure out solo how to code it.
 
Last edited:
Look through the ADO .NET tutorials in my sig.... one of them shows how to do inserts using SQL and a parameterized query.

Also it looks like all you are doing is moving the data from one set of text boxes to another.... I don't see it going anywhere into the datatable.
??

-tg
 
=)

Good deal I will try looking through your ado stuff.

The text boxes I am moving data to,, are invisible controls that have data bindings to a data set.
 
ok

PrivateConst MyCONNECTIONSTRING AsString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=final4600.mdb"

------------------------------------------
Dim DBConnection AsNew SqlClient.SqlConnection(MyCONNECTIONSTRING)
Dim strSQL AsString
Dim strVidId AsString
Dim strRentalNo AsString
Dim strQty AsString
Dim strBoolPurchase AsString
'set string
strVidId = txtVideoID.Text
strRentalNo = txtRentalNO.Text
strQty = txtQTYITEM.Text
If chkPurchase.Checked = TrueThen
strBoolPurchase = "TRUE"
Else
strBoolPurchase = "FALSE"
EndIf
strSQL = "INSERT INTO rental_videoproductitem(videoid, rentalno, purchase, qty) VALUES (" & strVidId & ", " & strRentalNo & ", " & strBoolPurchase & ", " & strQty & ")"
Dim InsertRentals AsNew SqlClient.SqlCommand(strSQL)

-------------------------------------------

This is how far I have gotten,,, I know my constant is wrong and I am most likely missing an execute type command.

 
Last edited:
All that's left is to .ExecuteNonQuery the InsertRentals.... assuming the data is correct, that should be OK.
Be sure to .Close the connection when done too.

-tg
 
Thanks!

TechG,

It is telling me that there is something wrong with my connection string. Could you take a look at that as well please =)

Your example shows going to sql server and mine is to jet 4.0 for MS Access

I tried to improvise but its telling me it doesnt recognize provider?

appreciate all the help...
 
I see what it is now.... use the OLEDBClient, not SQLClient.... SQLClient is for SQL Server. OLEDBClient is for any OLEDB compliant database (like access).

That's why it thinks the connection string is off.

-tg

ps- there's not need to pm me each time you reply. I do check back regularly, so I will see it.
 
Back
Top