Dim cnn As OleDbConnection
Dim cmdInsertStock As New OleDbCommand
cnn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & Application.StartupPath & "\Database.mdb")
Dim insStock As OleDbCommand = New OleDbCommand("Insert into Stock values ('" & txtModelNo.Text & "','" & txtDescription.Text & "','" & txtColour.Text & "'cnn)")
cnn.Open()
cmdInsertStock.ExecuteNonQuery()
cnn.Close()
error showing.....
executenonquery connection property has not been initialized
Saurav
problem with the follwing code
Page 1 of 15 Replies - 214 Views - Last Post: 29 November 2012 - 10:05 PM
Replies To: problem with the follwing code
#2
Re: problem with the follwing code
Posted 28 November 2012 - 06:01 AM
Hi, please check
OleDbCommand("Insert into Stock values ('" & txtModelNo.Text & "','" & txtDescription.Text & "','" & txtColour.Text & "'cnn)")
you forgot ","
Must be
OleDbCommand("Insert into Stock values ('" & txtModelNo.Text & "','" & txtDescription.Text & "','" & txtColour.Text & "',cnn)")
Hope was useful.....
OleDbCommand("Insert into Stock values ('" & txtModelNo.Text & "','" & txtDescription.Text & "','" & txtColour.Text & "'cnn)")
you forgot ","
Must be
OleDbCommand("Insert into Stock values ('" & txtModelNo.Text & "','" & txtDescription.Text & "','" & txtColour.Text & "',cnn)")
Hope was useful.....
#3
Re: problem with the follwing code
Posted 28 November 2012 - 06:03 AM
you did also join cnn with query, place comma(,) at the end of your query in order to use the OleDbCommand constructor overload.
Dim insStock As OleDbCommand = New OleDbCommand("Insert into Stock values ('" & txtModelNo & "','" & txtDescription & "','" & txtColour & "')", cnn)
This post has been edited by zeeshanef: 28 November 2012 - 08:52 AM
#4
Re: problem with the follwing code
Posted 28 November 2012 - 09:58 PM
zeeshanef, on 28 November 2012 - 06:03 AM, said:
you did also join cnn with query, place comma(,) at the end of your query in order to use the OleDbCommand constructor overload.
Dim insStock As OleDbCommand = New OleDbCommand("Insert into Stock values ('" & txtModelNo & "','" & txtDescription & "','" & txtColour & "')", cnn)
thanks zeeshanef...
but problem is same...can't find out the mistake...anyway...traying...to overcome...
Saurav
thanks zeeshanef...
but problem is same...can't find out the mistake...anyway...traying...to overcome...
Saurav
#5
Re: problem with the follwing code
Posted 29 November 2012 - 03:41 AM
It is because you initialize two different command objects. There is no use of cmdInsertStock because, you are creating and initializing new command object after this line.
After cnn.Open() put put this statement:
insStock.ExecuteNonQuery() and remove this cmdInsertStock.ExecuteNonQuery()
This should work:
After cnn.Open() put put this statement:
insStock.ExecuteNonQuery() and remove this cmdInsertStock.ExecuteNonQuery()
This should work:
Dim cnn As OleDbConnection
cnn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & Application.StartupPath & "\Database.mdb")
Dim insStock As OleDbCommand = New OleDbCommand("Insert into Stock values ('" & txtModelNo & "','" & txtDescription & "','" & txtColour & "')", cnn)
cnn.Open()
insStock.ExecuteNonQuery()
cnn.Close()
This post has been edited by zeeshanef: 29 November 2012 - 03:44 AM
#6
Re: problem with the follwing code
Posted 29 November 2012 - 10:05 PM
Hi adhikarysaurav
Use insStock.ExecuteNonQuery() instead of cmdInsertStock.ExecuteNonQuery()
Use insStock.ExecuteNonQuery() instead of cmdInsertStock.ExecuteNonQuery()
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|