New records in Datagrid to be inserted into SQL table. URGENT!

Discussion in 'ASP .Net' started by =?Utf-8?B?U0s=?=, Dec 10, 2003.

  1. Hi
    i m populating a datagrid with data from excel. is it possible to take the datatable in this dataset and create the same as a new table in SQl database. can some one gimme ideas to solve the same in different way
    =?Utf-8?B?U0s=?=, Dec 10, 2003
    #1
    1. Advertising

  2. =?Utf-8?B?U0s=?=

    Hermit Dave Guest

    Well you can write a generic function in your data access layer. first run a
    check to see if you have the table in your db, next iterate the dataset and
    start inserting records.

    * Get the Table myDT from the DataSet myDS
    * You will have to juggle a bit to create the create table statement from
    the DataTable
    * execute the create table and then do a "select * from tablename " from sql
    server
    * once you get the new dataset newDS,
    iterate the myDT (using i)
    call newDS.Tables[0].ImportRow(myDT.Rows
    once done importing the rows
    newDS.Tables[0].AcceptChanges

    i did start coding but it will take me a while plus i gotta leave for work
    now.. will do something of this sort in the evening and post it if necessary

    Chao,

    Hermit Dave


    "SK" <> wrote in message
    news:...
    > Hi,
    > i m populating a datagrid with data from excel. is it possible to take the

    datatable in this dataset and create the same as a new table in SQl
    database. can some one gimme ideas to solve the same in different ways
    >
    Hermit Dave, Dec 10, 2003
    #2
    1. Advertising

  3. =?Utf-8?B?U0s=?=

    onedaywhen Guest

    Here's one approach: connect to the Excel data source using Jet OLEDB
    and execute a SELECT..INTO query using the IN keyword to specify the
    SQL Server target e.g.

    SELECT *
    INTO [odbc;Driver={SQL
    Server};Server=MyServer;Database=MyDatabase;User
    ID=sa].[NewTempTable]
    FROM [Sheet1$]

    --

    "SK" <> wrote in message news:<>...
    > Hi,
    > i m populating a datagrid with data from excel. is it possible to take the datatable in this dataset and create the same as a new table in SQl database. can some one gimme ideas to solve the same in different ways
    onedaywhen, Dec 10, 2003
    #3
  4. i tried this
    testAdapter = New OleDbDataAdapter("SELECT * INTO [odbc;Driver={SQLServer};Server=MyServer;Database=InputData;uid=sa;].[NewTempTable] FROM [companyRelation22$]", strConn)
    which gave the error
    error : ODBC--connection to '{SQLServer}MyServer' failed.

    so, when i changed it to

    testAdapter = New OleDbDataAdapter("SELECT * INTO [SQLOLEDB;Driver={SQLServer};Server=MyServer;Database=InputData;uid=sa;].[NewTempTable] FROM [companyRelation22$]", strConn)

    it gives the following error
    error : Could not find installable ISAM

    the strConn connection parameter is proper.
    Can you please gimme more details on this as it is very urgent.
    =?Utf-8?B?c2s=?=, Dec 10, 2003
    #4
  5. hi
    can you please gimme the next steps to complete the task. i tried some insertcommands but of no use...
    =?Utf-8?B?c2s=?=, Dec 10, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lucky
    Replies:
    0
    Views:
    498
    lucky
    Jan 12, 2005
  2. Marc
    Replies:
    1
    Views:
    3,512
  3. James

    Add new records into SQL db via datagrid

    James, Oct 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    143
    Yan-Hong Huang[MSFT]
    Oct 3, 2003
  4. Marc
    Replies:
    1
    Views:
    220
  5. PT
    Replies:
    1
    Views:
    378
    Ken Schaefer
    Oct 7, 2004
Loading...

Share This Page