.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Insert array in SQL server

Posted By:      Posted Date: October 06, 2010    Points: 0   Category :ASP.Net


I am trying to insert a array into SQL with no luck. I get the string from a GPRS device that looks like this:

/WeightBridge.aspx?ReadeID=A1B5A0F5C4E4A1B5A0F5C4E4&TagID=45B6C56A90B645B6C56A90B6,A47B1256A45F0843,B49B1256A45F08FF,30 SEP 2010 21:33:59,I,&Custom=Vehicle Num

All I want to do is to split the TagID array and insert it with the rest of the string into a SQL table. The TagID array must inserted into the following colomns in the DB. TagID, TID, UserMemory, DateTime and Direction. After the insert I just give a response that the insert was successfull or failed. Thank you 

My code this far:

Imports System.Data.Sql
Imports System.Data.SqlClient

Partial Class WeightBridge
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    Private Sub insertValue()
        Dim sqlConn As New SqlConnection
        Dim strConnection As String
        Dim MyTagID As String

View Complete Post

More Related Resource Links

Insert into SQL Server with ajax file uploader


I am getting error in here 


Incorrect syntax near '987'

987 is where i put clientname.text

        Dim objCmd As New SqlCommand("Create Table " + clientname.Text + "(name Varchar(50), event Varchar(50), date1 datetime, username Varchar(50), password Varchar(50), " + strCommandText + ")", objConn)

        objCmd.CommandType = CommandType.Text

        Dim objConn2 As New SqlConnection("Data Source=dddd.db.2.hostedresource.com; Initial Catalog=mrpoteat; User ID=xxxxx; Password=xxxxxx;")
        Dim strCommandText2 As String = ""
        For index2 = 1 To Attachments1.Items.Count Step 1
            If String.IsNullOrEmpty(strCommandText2) Then
                strCommandText = "@pic" + index2.ToString()

Insert into Sql Server


The following code will Create the Table but Will not do an Insert Into.... Also It will not produce an error

Dim objConn As New SqlConnection("Data Source=mrpoteat.db.2798093.hostedresource.com; Initial Catalog=mrpoteat; User ID=xxxxxxx; Password=xxxxxxxx;")
        Dim strCommandText As String = ""
        For index = 1 To Attachments1.Items.Count Step 1
            If String.IsNullOrEmpty(strCommandText) Then
                strCommandText = "pic" + index.ToString() + Space(1) + "image"
                strCommandText += ",pic" + index.ToString() + Space(1) + "image"
            End If

        Dim objCmd As New SqlCommand("Create Table " + clientname.Text + "(

Insert Excel Data via File Upload into sql server database???

Hi all, I have requirement that User can Upload the Excel Sheet Data to sql server Database at once. How i do that Any Article or hint is apperciated.   Regards 

TSQL: Passing array/list/set to stored procedure (MS SQL Server)

Passing array/list/set to stored procedure is fairly common task when you are working with Databases. You can meet this when you want to filter some collection. Other case - it can be an import into database from extern sources. I will consider few solutions: creation of sql-query at server code, put set of parameters to sql stored procedure's parameter with next variants: parameters separated by comma, bulk insert, and at last table-valued parameters (it is most interesting approach, which we can use from MS SQL Server 2008). Ok, let's suppose that we have list of items and we need to filter this items by categories ("TV", "TV game device", "DVD-player") and by firms ("Firm 1", "Firm2", "Firm 3). It will look at database like this So we need a query which will return us list of items from database. Also we need opportunity to filter these items by categories or by firms. We will filter them by identifiers. Ok, we know the mission. How we will solve it? Most easy way, used by junior developers - it is creating SQL-instruction with C# code, it can be like this List<int> categories = new List<int>() { 1, 2, 3 };   StringBuilder sbSql = new StringBuilder(); sbSql.Append( @" select i.Name as ItemName, f.Name as FirmName, c.Name as CategoryName from Item i inner join Firm f on i.FirmId =

Insert/Update OLE Attachment(Binary datatype) using SQL server 2000

Hi All, In the same senario how we can Insert/Update OLE Attachment(Binary datatype)  from one source table to other destination table by using SQL Server 2000 not with C# fronend code. Appreciated if you can give fix on this regads, Divakar.

(SQL Server 2008) Exporting entire databases to SQL CREATE/INSERT statements

Hi All, I'm looking for a way to export SQL Server 2008 (Express or otherwise) databases to CREATE/INSERT statements.  I've seen a million threads (give or take) with instructions for creating large (often illegible) TSQL scripts for the task.  However, I'm hoping that this isn't the only way by which to do it.  I have need to regularly back up the data from existing MS SQL Server DBs (which are used by some of our standard apps) to various other MySQL and PostgreSQL databases (which are used by PHP and Rails web front ends).  I need to export them from MS SQL Server 2008 to a general format (i.e. INSERT statements) and perform regex edits on the file as necessary. FYI, I've written a few applications that connect to the various DBs over ODBC, etc. and transfer the data row by row.  You can image how painful this process is... I realize that there are many tools that do this.  However, most of them approach the issue from the standpoint of migration, and not that of regularly scheduled backups.  Also, this tool will need to eventually be distributed so having to purchase a license for the migration app for each person/group simply isn't feasible. Anyway, if you guys have a quality, straightforward solution to this issue, it would certainly be appreciated. Best.

Insert Into SQL Server inside a For Each - Next Statement

I have the following code to For each Item in the file uploader, Insert Into database.... but It doesnt work in the For Each Statement but if i take it out of the For Each statement it works.   For Each item As AttachmentItem In Attachments1.Items            Dim objConn2 As New SqlConnection("Data Source=XXX")            objConn2.Open()            Dim objCmd2 As New SqlCommand("INSERT INTO clientport (name, event, date1, username, password, path)" & "VALUES (@name, @event, @date1, @username, @password, @path)", objConn2)                                 objCmd2.Parameters.AddWithValue("@name", clientname.Text)            objCmd2.Parameters.AddWithValue("@event", [event].Text)            objCmd2.Parameters.AddWithValue("@date1", [date].Text)            objCmd2.Parameters.AddWithValue("@username", username.Text)  &nbs

insert query from ms SQL server into a mysql linked server

INSERT into openquery(dbserver1MySQL,'select * from graham.lookup_in_table') select * from NavteqAPAC.dbo.Admin_Names   is giving me the following error! Please help me   OLE DB provider "MSDASQL" for linked server "dbserver1MySQL" returned message "[MySQL][ODBC 5.1 Driver][mysqld-5.1.49-community]Commands out of sync; you can't run this command now". Msg 7343, Level 16, State 2, Line 1 The OLE DB provider "MSDASQL" for linked server "dbserver1MySQL" could not INSERT INTO table "[MSDASQL]".

Insert 5000 records to Sql server using ado.net at once

Question Details:-I have 2 databases. DB1 and DB2DB1 contains a table having colums.   1. TF2. OD3. SD4. FD5. ES6. EF7. Comments-------------------------------DB2 table TB1 has the same fields but diff column names1. TotalFloat 2. OriginalDuration 3. StartDate 4. FinishDate 5. EearlyStart 6. EearlyFinish7. strComments__________________________________DB1 table has arround 7000 rows. What my requirement is: Copy all the rows from DB1.TB1 into DB2.tblTargetWhat I am doing is?Looping all the records from the db1 table and by using InsertCommand adding all thoses records to a dataset.Now using Adapter.Update method,,,, all the records are fethecd to target database table. but when Adater.Update() method executes, it paused there for 3-5 minutes.Can I acheieve this in a quick manner? Please help me out of this, as this ia very critical task.I would like  to achieve this via coding.Thanks and Best Regards,Dev

error in insert hebrew data into sql server 2005

Hello, am trying to insert data in hebrew language into sql server 2005 but it appears like this ???????????? can i know how i can fix the problem plz???? thank u

before insert equivalent in sql server

Is there an equivalent of "Before insert" trigger of Oracle in SQL Server 2005. I tried "Instead of" trigger but It does not actually insert into the main table and executes the statements defined in the trigger. Currently I hav two after insert triggers in sql server both of which are getting called upon insert. I want to differentiate them as I am doing it in ORACLE by defining one of the two as BEFORE INSERT trigger.

How to do a parameterized bulk insert into SQL Server 2008 R2 from C# (.NET 4.0)

Hi, I'm trying to execute a BULK INSERT with a parameterized SqlCommand from a C# .NET 4.0 project. This is the code: private System.Data.SqlClient.SqlCommand sqlCmd2; private string sqlCmd2String = "BULK INSERT ExchangeTrackingLogs.dbo.ParsedLogs FROM @name WITH (FIELDTERMINATOR=',', ROWTERMINATOR='\n', FIRSTROW=2)"; private System.Data.SqlClient.SqlParameter[] sqlCmd2Params = new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.VarChar) }; (...) sqlCmd2Params[0].Value = source; sqlCmd2.Parameters.Clear(); sqlCmd2.Parameters.AddRange(sqlCmd2Params); sqlCmd2.ExecuteNonQuery(); where source is a string containing the full path to a file, i.e. a value "C:\\TEMP\\MSGTRK20100701-1.LOG_EXHUB01". When I execute this code, I get an Exception with Message "Incorrect syntax near '@name'." In the database trace I see an RPC:Completed event with TextData equal to exec sp_executesql N'BULK INSERT ExchangeTrackingLogs.dbo.ParsedLogs FROM @name WITH (FIELDTERMINATOR='','', ROWTERMINATOR='' '', FIRSTROW=2)',N'@name varchar(36)',@name='C:\TEMP\MSGTRK20100701-1.LOG_EXHUB01' I tried using verbatim string literals, but doesn't seem to help. Any idea?

Insert Into SQL Server, With Current File Uploader Count

I have a Multiple File Uploader named "Attachments1" , and to get the cound I used "Attachments1.items.count"... then I have a Insert Into Command for SQL Server, that Inserts information into the table for every item in "Attachments1", you can see the below code... For Each item As AttachmentItem In Attachments1.Items             Dim objConn2 As New SqlConnection("Data Source=XXX")             objConn2.Open()             Dim objCmd2 As New SqlCommand("INSERT INTO clientport (name, event, phone, email, date1, password, path, path2, filename, number)" & "VALUES (@name, @event, @phone, @email, @date1, @password, @path, @path2, @filename, @number)", objConn2) But for the "number" Column, I would like to insert the Count for that file... For example if Attachments1 has 3 files it will insert into the database the time (which works fine)  the probem is the number column doesnt make file1 for the first file, file 2 for the second file, and file3 for the third file... Instead it puts file3 for all three rows when it Inserts into the DB.  my code is below to get the count.   Dim strcommandtext As String = ""    

SQL Server 2K5 - INSERT INTO Script crash with no specific error

Hi, I need to run a sql statement that insert data into a table. I have about 14000 line to insert. In SQL Management studio, I did a script like that : INSERT INTO [TableName] (Field1,fireld2,field3,...) Select 'Values1','Values2','Value3',.... UNION ALL Select 'Values1','Values2','Value3',.... UNION ALL Select 'Values1','Values2','Value3',.... UNION ALL . . . When I try to insert around 1000 line and more, the script crash with no specific error code or message. I only see the message in the status bar saying, the script ended with error. Is there a way to avoid having that error ? ThanksRichard Martin Web Developer / BI Developer

XMLDML insert is dog slow for real inserts in SQL Server 2005

I put together a little sample after noticing my XML solution was taking more than three seconds every time I inserted something over 20 records with a reasonable number of attributes. XML updating is apparently not ready for production code in 2005. This is faster in SQL Server 2008, and might work for some applications, but you'd actually write the code a little differently there. In any case, it's far slower than writing out the string yourself. Anyhow, if anyone asks you why you're not using XML.modify('insert in SQL Server 2005, you can run this for them.  DECLARE @now DATETIME, @then DATETIME, @elapsed INT, @now_disp NCHAR(24); SET @now = GETDATE(); SET @now_disp = CONVERT(NCHAR(24), @now, 126); RAISERROR('starting timer at %s', 11, 1, @now_disp) WITH NOWAIT; DECLARE @root XML, @insert NVARCHAR(MAX), @counter INT, @child XML, @att NCHAR(3), @attdex tinyint; SET @root = '<root/>'; SET @counter = 24; WHILE @counter < 26 BEGIN SET @counter = @counter + 1 SET @child = CAST('<child/>' AS xml) SET @attdex = 0; WHILE @attdex < @counter BEGIN SET @attdex = @attdex + 1; SET @att = CHAR(96 + @attdex) + 'ow'; SET @insert = 'SET @child.modify(''insert attribute ' + @att + ' {"value"} into (/child)[1]'');'; EXEC sys.sp_executesql @insert, N'@child xml OUT', @child

Hi.how I can to insert value from sql db to array ?


I have combobox wich biding data from sql db

I use ado.net

I wont to insert values wich i get from ado.net code to array ?

how i can do that?


DataTable dt = new DataTable();


SqlConnection con = new SqlConnection("Data Source=D-PC;Initial Catalog=DMS;In

How to create a server control array


Let's say I have 50 different SQL SELECT statements which each one returns one integer value...

e.g. SQL 1 = select count(row) from table where condition = 'a'

      SQL 2 = select count(row) from table where condition = 'b'

      .....  so on  .....

      SQL 50 = select count(row) from table where condition = 'zzz'


If I have 50 labels (server control) and want to put each SELECT result to corresponding labels by using a FOR LOOP.


      for (int i=0; i<49; i++)


            // connect to the database and run each SELECT statement

            // store each result to corresponding label.  (Result 1 -> Label 1, Result 2 -> Label 2, .........., Result 50 -> Label 50)



I have all 50 SQL SELECT statements to run in a loop and each one has the result that I want.

I need to display all 50 results in 50 different labels (one-to-one) and just don't know how I need to name each label, so that I can use them like a array.


In VB6 (back in th

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend