By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

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

P: n/a
SK
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

Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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[i]
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" <an*******@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
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

Nov 18 '05 #2

P: n/a
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" <an*******@discussions.microsoft.com> wrote in message news:<B8**********************************@microso ft.com>...
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

Nov 18 '05 #3

P: n/a
sk
i tried this
testAdapter = New OleDbDataAdapter("SELECT * INTO [odbc;Driver={SQLServer};Server=MyServer;Database=I nputData;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;Databa se=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.

Nov 18 '05 #4

P: n/a
sk
hi
can you please gimme the next steps to complete the task. i tried some insertcommands but of no use...

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.