Insert command in SQL with

Hi I am a new in ASP .NET programming I faced a problem to insert integers with other types of variables in my database from my programs.

I have only permission to pass the SQL command to my server.

As an example I have one table TestTable with two column one is integer and one is varchar named as ID and Fname

I can insert any string that table but when I trying to insert integer and string then it shows an error.

Dim strInsertSQL As String = "INSERT INTO TestTable (ID,Fname) VALUES (" & iID & “,’” & strFname & “’)”Dim conStr As String = String.EmptyconStr = ConfigurationSettings.AppSettings("connectionString")Dim con As New SqlConnection(conStr)Dim sqlCommand As SqlCommand = con.CreateCommand()con.Open()sqlCommand.CommandText = strInsertSQL Dim r As Int16 = sqlCommand.ExecuteNonQuery()con.Close()here iID is an Int32 and strFname is a String variable.I was also trying with iID.ToString() it also create problem since in data table column type is integer.Can you help me to solve the problem?


8/18/2008 10:10:54 PM 29906 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 23

Hi aamexplore,

One issue I see is that ExecuteNonQuery returns an Int32, so your Dim r as Int16 should be Dim r as Int32. If that doesn't work, please post the exception you are receiving.

EDIT: Also, verify that the TestTable.ID field is not an identity field. If you try to insert a value into an identity field while IDENTITY INSERT is ON you will receive an error.


Please remember to click "Mark as Answer" on the posts that helped solve your issue.
8/18/2008 10:34:19 PM


     It will be easy to provide the solution if you can give more details on error message.


If this post was useful to you, please mark it as answer. Thank you!
8/19/2008 4:24:09 AM

Thanks now it is working, u r right, its identity was on, now I make it off and it working great. Thanks again for help

8/19/2008 1:46:50 PM

Similar Artilces:

Insert SQL on Sql Command
i'm using an sql command for insert query it looks like this cmd=new sqlcommand("insert into tblname values('" & textbox1.text & "')",cn) cmd.executereader the problem is if i type a singlequote or double quote an error is throwing,invalid syntax .... how can i s'rt out it with out using a sql stored procedure thanks in advance PrasantHI think therefore i'mvPras© Hi, try replacing the single quotes present in your input with double single quotes ... example below: string sqlInput = textbox1.text.Replace("'","''...

Attach SQL DB to SQL Server 2005 using VB.Net
Is there any way to attach a SQL DB to SQL Server 2005 using VB.Net?  If so can you also set security? Can you rephrase your question? Attach SQL DB from which version of SQL server ? Look up books online for sp_attachdb and sp_detachdb.***********************Dinakar NethiLife is short. Enjoy it.*********************** I have a DB that was created in SQL Server 2005.  I have a website that displays data from systems all over the world.  Each system sends it's data to it's own DB.  The customer can then go to a website and see the data at real time.  What ...

Sql Server Script File(.sql) Execution by Code
I have a problem. I m working on "light weight sql server"  project.   and i want to execute .sql file through code with the help of sqldmo library and sqlns namespace. but i donot know any method to directly execute the .sql file. i am successfully making the full script of select database of sql server.   please help me.... thanks.... Hi, You can use SQL-DMO object in your .net projects by referencing Sqldmo.dll  file which is in  C:\Program Files\Microsoft SQL Server\80\Tools\Binn  folder is default installation parameters are used. I...

SQL Server Reporting Services for SQL SERVER 2000 AND Visual Studio.NET 2005 .NET 2.0
Hi, Which version of SQl Server Reporting Services will work with SQL SERVER 2000 in pararrel with ASP.NET 2.0 (.NET 2.0 framework)?  Thanks, Azam HighOnCodingWanna get high! Hi, Okay I got the answer. Yes, we can use the SQL SERVER 2005 Reporting Services with SQL SERVER 2000. HighOnCodingWanna get high! ...

how to insert sql stored procedure into code??
I am trying to create a paged web site from my database file. for that i found an appropriate sql code. the only thing i don't know is how to declare this sql inside the vb. is it supposed to be in the same .aspx file or in another one?? pls help if you know. thank you so much. here's the sql stored procedure: ------------------------------------------------------------ CREATE PROCEDURE sp_PagedItems ( @Page int, @RecsPerPage int ) AS -- We don't want to return the # of rows inserted -- into our temporary table, so turn NOCOUNT ON SET NOCOUNT ON --Cr...

Insert Data into sql DB using backend
Hi. I need too use my backend to insert data into my database from seveeral controls on the page. I have tried writing some code to do this but i am a beginner, and i am completely stuck. Heres what i have so far   Dim userid As String = DropDownList2.SelectedValue Dim username2 As String = DropDownList1.SelectedValue Dim date2 As String = Calendar1.SelectedDate Dim invoiceid As Integer = TextBox1.Text Dim amount As Decimal = TextBox2.Text Dim conn As String = ConfigurationManager.ConnectionStrings("U...

Sending SMS using or using or
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Hi there! I only recently started using ASP.Net. I really appreciate the fact that i now can cleanly seperate code from presentation. This is the best thing in the world ever! There is a problem however... Visual Basic. I have never used it before. Only VBscript. Communicating with my Database tunred into a nightmare overnight! Could somebody PLEASE suggest some book or tutorial or something to help me out. I need to write complex tSQL strings but i cant seem to come right. MySQL did release in their manual a full help section on writing SQL strings for their dat...

Sql Insert information from 1 table into another on the fly. VB.NET
This is probably a really simple question, but hey! this is what this forums about I have this code, which is inserting data into 2 different tables from textboxes. The problem is. the "login" table autoincrements but the "details" table needs to have an id the same as the matching row in the login table (im using it for sessions for user profiles)The example here is of a registration page and it inserts your details as stated above. How do i get the value "user_id" from the second insert statement (which is an autoincrement so its not in the code) and inse...

how do i insert data into sql server using data from textboxes and sql connection and sql command
anyone can give me a simple explaination and code.. Thanx in advance Take a look @ Sample Code: How to add...Sushila Bowalekar PatelVisual ASP/ASP.NET MVP There are a lot of tutorials out there, but I know they can be a bit confusing as they all approach things slightly differently. Basically a nice simple version would go like this:' *** First set up your connectionDim conConnection As New SqlConnection("server=servername;database=yourdatabase;uid=yourname;pwd=yourpassword;")' *** This line takes care of your sommand text and command connection in one ...

INSERT data into SQL table... TableAdapter Commands or SQL Commands? Which is best?
I've been working on some unbound data forms, and trying to decide what is best when inserting and/or updating a record into a SQL table.    I can successfully use SQL commands to insert data from VS2008 into a sql table on the server, doing something such as... Dim conn As New SqlConnection("server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=YourDatabaseName")Using conn conn.Open() Dim cmd As New SqlCommand("UPDATE tableName SET folderName = @folder WHERE id = @id", conn) cmd.Parameters.AddWithValue("@folder", txtFolder.Te...

how to insert all data from dataset to a temporary table in sql server database
I always get solutions for my question from the forum , thanks for all your help. Question is i have select some data from a database in server 1 and save it in to a DataSet in now i need to create a temporary table in server 2 test database and insert all rows in DataSet. I know I can read row by row in DataSet.Table(0) and execute a insert statement for each row. but i think this is time consuming. Is there any way that I can transfer all data in DataSet to a temporary table at once. need your help please. I am selecting data from Server 1 Datababse (original1) as follows &n...

Working in VB.Net 2005 inserting NULL into a field in Microsoft SQL Server 2005
I am update/inserting records threw a web form in I need to insert 'NULL'  into my microsoft sql server database.  I am not talking about the below line of code where website is the name of my paramater.  If i do that it will just place a blank into that field in the database.  If i dont enter anything into that textbox I want it to to say NULL in that field. So if I go into the actual table in the SQL Server Management Studio and look at the website field of the recored I just added or updated and did not type anything into the web site textbo...

connection between and SQL
 I would like to use VB2005.Net (Express) connect to MSSQL2005 (Express), how can I do it? I can complete the development via local database (with "attach" method in connection string).  I try the remote connection via client machine with string ("Data Source=w2000-vm1\SQLEXPRESS;Initial Catalog=ABC;Integrated Security=SSPI;Connect Timeout=30;User Instance=True") and it was still pop up error shown below (using web deployment for the client machine).  But I can do the same with Excel VBA sucessful. Error Message: See the end of this message for details o...

Web resources about - Insert command in SQL with -

Command - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Cameron Carpenter review: Bells and whistles matched by a command of the organ
It's certainly no exaggeration to call Cameron Carpenter's command of six keyboards (five for hands, one for feet) "genius". Purely in cognitive ...

Adele eclipses Taylor Swift to take command of the pop world
Adele Adkins is the first person to top the ARIA singles and albums charts in the same week since Swift exactly one year ago.

Command your club to victory in Sega’s Football Manager Mobile 2016
... How long can you survive on the Last Horizon? , and Dig, explore and collect stars in Starlit Adventures . Football Manager Mobile 2016 Command ...

How to craft your own custom voice commands for Amazon Echo's Alexa
With a little help from IFTTT, you can teach Alexa all sorts of new tricks. Here's how to get started.

Germany’s Second In Command Denounces Saudi Funding Of Radical Islam Abroad
Germany’s Second In Command Denounces Saudi Funding Of Radical Islam Abroad

Bethesda: Fallout 4 console commands 'not supported or recommended' on PC
In a very Bethesda-like fashion, messing around with console commands on the PC version of Fallout 4 might completely bug out your game more ...

Amazon Echo owners can create custom voice commands with IFTT
... item to your shopping list is pretty cool, but there comes a point where you start to feel the limits of the Echo's pre-programmed voice commands. ...

Chinese Hacker Group Uses Dropbox for Malware Command and Control
NEWS ANALYSIS: The current malware threat isn't targeting U.S. interests now, but the hacker group could easily turn its attention in that direction ...

Resources last updated: 12/16/2015 6:54:04 AM