Datagrid to sql database

  • Thread starter Thread starter EMW
  • Start date Start date
E

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
 
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/quickstart/CompactFramework/doc/ppcformproperties.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
 
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
 
-----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 to
find it in the jungle of MSDN.

thanks!
Eric
REPLY :
for x = 1 to datagrid1.Items.Count
insert into SQLTABLE
values ()
end
 
Back
Top