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

Datagrid to sql database

P: n/a
EMW
How can I put everything that is in a datagrid into a SQL server database
(which should be readable by an PocketPC program)?

There is probably a simple solution for it, but as always it is difficult to
find it in the jungle of MSDN.

thanks!
Eric
Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

I believe you are adding new elements to datagrid and
would like to save these new elements to database.

You can frame insert SQL and execute it using Command
object on the click event handler of a button that you
are using for inserting the new record.

The following link have a similar example
http://www.dotnetjohn.com/articles/articleid27.aspx

Thanks,
Gopi
-----Original Message-----
How can I put everything that is in a datagrid into a SQL server database(which should be readable by an PocketPC program)?

There is probably a simple solution for it, but as always it is difficult tofind it in the jungle of MSDN.

thanks!
Eric
.

Jul 21 '05 #2

P: n/a
It really depends on how you populated the grid. If you used a Select
Statment and bound it to a datatable/dataset via a DataAdapter, then you
can use a CommandBuilder or DA Configuration wizard or write your own update
logic. Once you have an update command, you can call endcurrentedit and
fire a da.UPdate.

If you constructed the Dataset manually, or read it from an XML, you'll need
the diffgram option so you can know what has been changed. You obviously
don't want to submt things that haven't changed = if you tried adding them,
you would get a key violation if your table was keyed properly.

These Quickstarst shoud address yoru specific problem (basically, with a few
small difference, you c an use the same code to populate and a Datagrid and
send back the updates on a PPC that you would with the full framework.
http://samples.gotdotnet.com/quickst...roperties.aspx

You may want to check out some of the work at www.opennetcf.org and
www.devbuzz.com . Both sites have a some great samples of stuff that you may
want to implement if you are doing serious PPC development. Also, you may
want to check out the Compact Framework Core Reference by Wrigley and
Wheelwright, the Definitive Guide to the Compact Framework by Fergus and
Roof and Rob Tiffany's new book on SQL CE ---
http://www.devbuzz.com/content/books.asp

HTH,

Bill
"EMW" <so*****@microsoft.com> wrote in message
news:3f**********************@dreader2.news.tiscal i.nl...
How can I put everything that is in a datagrid into a SQL server database
(which should be readable by an PocketPC program)?

There is probably a simple solution for it, but as always it is difficult to find it in the jungle of MSDN.

thanks!
Eric

Jul 21 '05 #3

P: n/a
EMW
Thanks for answering.

I populated the datagrid by reading a EXCEL file into a dataset and then I binded it to the datagrid.
After that I changed some cells.

I don't think the dataset is now updated and I also don't know how to do that (I'm really a newbee on this .NET stuff)
So either I get everything from the datagrid directly into the SQL database or I first update the dataset and then get it from the dataset into the SQL database.

here is the code that does this:

Dim MyXL As Object

Dim ExcelWasNotRunning As Boolean

Dim filenaam As String

Dim openFileDialog1 As OpenFileDialog

Dim rowcount As Integer

Dim aa, bb, cc

openFileDialog1 = New System.Windows.Forms.OpenFileDialog

openFileDialog1.DefaultExt = "xls"

openFileDialog1.Filter = "Excel sheet files (*.xls)|*.xls"

Dim result As DialogResult = openFileDialog1.ShowDialog()

If (result = DialogResult.Cancel) Then Exit Sub

filenaam = openFileDialog1.FileName

Me.Cursor.Current = Cursors.WaitCursor

Dim DS As System.Data.DataSet

Dim MyCommand As System.Data.OleDb.OleDbDataAdapter

Dim MyConnection As System.Data.OleDb.OleDbConnection

MyConnection = New System.Data.OleDb.OleDbConnection( _

"provider=Microsoft.Jet.OLEDB.4.0; " & _

"data source=" & filenaam & "; " & _

"Extended Properties=Excel 8.0;")

' Select the data from Sheet1 of the workbook.

MyCommand = New System.Data.OleDb.OleDbDataAdapter( _

"select * from [bts$]", MyConnection)

DS = New System.Data.DataSet("sitelijst")

'DS.Tables.Add(New DataTable("sitelijst"))

Try

MyCommand.Fill(DS, "bts")

Catch ex As Exception

Exit Try

Finally

MyConnection.Close()

End Try

MyConnection = Nothing

MyCommand = Nothing

dgTabel.SetDataBinding(DS, "bts")

dgTabel.Refresh()

rowcount = DS.Tables(0).Rows.Count

Me.lblRows.Text = "Totaal sites: " & CStr(rowcount)

For aa = 0 To rowcount - 1

bb = Trim(dgTabel.Item(aa, 0))

If Val(bb) < 1000 Then bb = Trim("0" + bb)

dgTabel.Item(aa, 0) = bb

Next

Me.Cursor.Current = Cursors.Default

dgTabel.CurrentCell = New DataGridCell(0, 0)

dgTabel.Refresh()

So after this the info in the datagrid should be saved in a SQL database.
It doesn't matter that only that has been changed is updated, everything should be written in the database file.

So this is my problem...

thanks,
Eric

"William Ryan" <do********@nospam.comcast.net> schreef in bericht news:%2*****************@tk2msftngp13.phx.gbl...
It really depends on how you populated the grid. If you used a Select
Statment and bound it to a datatable/dataset via a DataAdapter, then you
can use a CommandBuilder or DA Configuration wizard or write your own update
logic. Once you have an update command, you can call endcurrentedit and
fire a da.UPdate.

If you constructed the Dataset manually, or read it from an XML, you'll need
the diffgram option so you can know what has been changed. You obviously
don't want to submt things that haven't changed = if you tried adding them,
you would get a key violation if your table was keyed properly.

These Quickstarst shoud address yoru specific problem (basically, with a few
small difference, you c an use the same code to populate and a Datagrid and
send back the updates on a PPC that you would with the full framework.
http://samples.gotdotnet.com/quickst...roperties.aspx

You may want to check out some of the work at www.opennetcf.org and
www.devbuzz.com . Both sites have a some great samples of stuff that you may
want to implement if you are doing serious PPC development. Also, you may
want to check out the Compact Framework Core Reference by Wrigley and
Wheelwright, the Definitive Guide to the Compact Framework by Fergus and
Roof and Rob Tiffany's new book on SQL CE ---
http://www.devbuzz.com/content/books.asp

HTH,

Bill
"EMW" <so*****@microsoft.com> wrote in message
news:3f**********************@dreader2.news.tiscal i.nl...
How can I put everything that is in a datagrid into a SQL server database
(which should be readable by an PocketPC program)?

There is probably a simple solution for it, but as always it is difficult

to
find it in the jungle of MSDN.

thanks!
Eric


Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.