473,379 Members | 1,190 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Datagrid to sql database

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
3 1702
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gamze | last post by:
Hi, How can i get values from datagrid to combobox and should select the same name as in datagrid row on the combobox control In my vb.net windows application ,i have combobox which is...
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
4
by: Rod | last post by:
I posted a message to this group yesterday asking how to pass parameters to a web form that is the source of an IFrame on a parent web form. I've gotten my answer, and it works. Thanks! Now I...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value....
4
by: cooltech77 | last post by:
Hi, I am trying to build the following functionality in the datagrid. I have a lot of columns in the datagrid which are being populated from the database and the user needs to scroll...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.