473,473 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

cmd.executenonquery()

1 New Member
To insert a data into the data base, to the best of my knowledge the code i have written is correct.. but i frequently get this error.. hope I will receive a proper solution for my query.

The code is:

Expand|Select|Wrap|Line Numbers
  1. imports system.data.oledb
  2.  
  3. dim cn as new oledbconnection
  4. dim cmd as new oledbcommand
  5.  
  6. under the insert button:
  7. cn.open()
  8. cmd.connection=cn
  9. cmd.connectionstring=""
  10. cmd.commandtype=data.commandtype.text
  11. cmd.commandtext="insert into tablename values("")"
  12. msgbox("inserted")
  13. cn.close()
thanks,
Preethy
Apr 6 '10 #1
3 3299
MrMancunian
569 Recognized Expert Contributor
but i frequently get this error
What error?

cmd.connectionstring=""
Why is there no connectionstring?

Take a look at Insight: Creating database connections without using wizards, How To Use A Database In Your Program Part I and How To Use A Database In Your Program Part II. That should help you.

Steven
Apr 7 '10 #2
semomaniz
210 Recognized Expert New Member
Please show us the entire code. Best way is to replace the actual table names and connection string with bogus values. And also use try catch block its really handy
Apr 9 '10 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Line 11 has a problem with it.
You cannot have:
Expand|Select|Wrap|Line Numbers
  1. cmd.commandtext="insert into tablename values("")"
Do you see why?
Your string is messed up.....

You should probably review the articles that MrMancunian linked you to.

-Frinny
Apr 13 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mark | last post by:
Hi, I have a sqlCommand object that I use to execute an SQL statement. I thought I could use the ExecuteNonQuery to test for the number of rows returned by the sql command but it does not seem to...
1
by: Mark | last post by:
It appears that you can only retrieve an Output parameter from a SQL Server stored procedure when using the ExecuteNonQuery of the SqlCommand class, and cannot use the ExecuteReader() method. In...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
5
by: Paul Aspinall | last post by:
Hi I have a Stored Proc in SQL server, which creates a record key when a record is created. I want to return the value back to my code, once the record has been created. I am using SQLHelper...
1
by: Matthew Louden | last post by:
I just tried to create a simple ASP.NET application to add record to the SQL Server database. However, it has run time error on Line 88: objCommand.ExecuteNonQuery() Any ideas?? Please help!!...
0
by: johnnymack0730 | last post by:
Hello - I am currently working on an asp.net application that needs to be able to update an access table using ExecuteNonQuery method. I have all the code setup, it runs, there are no errors...
4
by: MDW | last post by:
Hey all. I'm confused. I'm trying to add a single record into an Access 2000 database using ASP.Net. Here is the code: objConn = New OleDbConnection(strConnect) objConn.Open objCommand =...
2
by: jdb | last post by:
Hi, I am adding a record to the database using an ExecuteNonQuery, which adds without problem. Now after the record is added I run a method passing in some info as well as the curretnly opened...
3
by: keithb | last post by:
What can I put in a stored procedure to control what gets returned by command.ExecuteNonQuery()? I already tried this: param = comm.CreateParameter(); param.ParameterName = "@Success"; ...
2
by: TheSteph | last post by:
Hi I have a SQLCommand that do updates on a table. I have a loop where I set the parameters then I call ExecuteNonQuery. For . { . Set the SQLCommand's Params Values;
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.