473,395 Members | 2,006 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,395 software developers and data experts.

textbox, datagrid and datatables all not updating

Hi,

I'm having a problem getting data into my db using datatable and
commandbuilder.

The 'cars' table in my sql server holds: employeeID, carID, make,
model, year.

I have a datagrid with car info in it. The grid is bound to a
datatable called dtAutos. The grid includes make, model, year. The
grid updates, adds a new row just fine into the db, but without the
employeeID and/or CarID info. If I manually put an employeeID or
CarID into the table, the row will appear.

I have textboxes with the employeeID and CarID data. They are bound to
a datatable called dtAssignments.

When I add a new car to the datagrid and click the update button, I
want the new row to have the employeeID from the textbox inserted
into the db along with the make, model and year.

Here is how I'm attempting to do this:

Sub GetCommands()
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)
da.InsertCommand = cb.GetInsertCommand
da.DeleteCommand = cb.GetDeleteCommand
da.UpdateCommand = cb.GetUpdateCommand
End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click

Dim CurrentRow As DataRow
Dim iPos As Integer

dtAutos = dsAutos.Tables("cars")
CurrentRow = dtAutos.Rows(iPos)

CurrentRow("carid") = txtCarID.Text
CurrentRow.AcceptChanges()

Try
GetCommands()
da.Update(dtAutos)

Catch ex As Exception
MsgBox(ex.ToString)
Clipboard.SetDataObject(ex.ToString, True)
End Try
grdAutos.Refresh()

End Sub

Can anybody help? If you need clarification, post back, I'm very
confused as to why I can't read info straight from a textbox into a
db...
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #1
5 1524
If you call AcceptChanges right before Update, then the changes will never
go back to the db. AcceptChanges resets the rowstates to unchanged so
calling Update all year won't do anything.
http://www.knowdotnet.com/articles/efficient_pt4.html

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
"sparkle" <hr****@hra.co.santa-cruz.ca-dot-us.no-spam.invalid> wrote in
message news:40**********@Usenet.com...
Hi,

I'm having a problem getting data into my db using datatable and
commandbuilder.

The 'cars' table in my sql server holds: employeeID, carID, make,
model, year.

I have a datagrid with car info in it. The grid is bound to a
datatable called dtAutos. The grid includes make, model, year. The
grid updates, adds a new row just fine into the db, but without the
employeeID and/or CarID info. If I manually put an employeeID or
CarID into the table, the row will appear.

I have textboxes with the employeeID and CarID data. They are bound to
a datatable called dtAssignments.

When I add a new car to the datagrid and click the update button, I
want the new row to have the employeeID from the textbox inserted
into the db along with the make, model and year.

Here is how I'm attempting to do this:

Sub GetCommands()
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)
da.InsertCommand = cb.GetInsertCommand
da.DeleteCommand = cb.GetDeleteCommand
da.UpdateCommand = cb.GetUpdateCommand
End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click

Dim CurrentRow As DataRow
Dim iPos As Integer

dtAutos = dsAutos.Tables("cars")
CurrentRow = dtAutos.Rows(iPos)

CurrentRow("carid") = txtCarID.Text
CurrentRow.AcceptChanges()

Try
GetCommands()
da.Update(dtAutos)

Catch ex As Exception
MsgBox(ex.ToString)
Clipboard.SetDataObject(ex.ToString, True)
End Try
grdAutos.Refresh()

End Sub

Can anybody help? If you need clarification, post back, I'm very
confused as to why I can't read info straight from a textbox into a
db...
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 20 '05 #2
Ya just couldnt resist helping sometone called 'Sparkle' could ya Bill !

Hows things eh ?

OHM

"William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
news:O7**************@TK2MSFTNGP10.phx.gbl...
If you call AcceptChanges right before Update, then the changes will never
go back to the db. AcceptChanges resets the rowstates to unchanged so
calling Update all year won't do anything.
http://www.knowdotnet.com/articles/efficient_pt4.html

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
"sparkle" <hr****@hra.co.santa-cruz.ca-dot-us.no-spam.invalid> wrote in
message news:40**********@Usenet.com...
Hi,

I'm having a problem getting data into my db using datatable and
commandbuilder.

The 'cars' table in my sql server holds: employeeID, carID, make,
model, year.

I have a datagrid with car info in it. The grid is bound to a
datatable called dtAutos. The grid includes make, model, year. The
grid updates, adds a new row just fine into the db, but without the
employeeID and/or CarID info. If I manually put an employeeID or
CarID into the table, the row will appear.

I have textboxes with the employeeID and CarID data. They are bound to
a datatable called dtAssignments.

When I add a new car to the datagrid and click the update button, I
want the new row to have the employeeID from the textbox inserted
into the db along with the make, model and year.

Here is how I'm attempting to do this:

Sub GetCommands()
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)
da.InsertCommand = cb.GetInsertCommand
da.DeleteCommand = cb.GetDeleteCommand
da.UpdateCommand = cb.GetUpdateCommand
End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click

Dim CurrentRow As DataRow
Dim iPos As Integer

dtAutos = dsAutos.Tables("cars")
CurrentRow = dtAutos.Rows(iPos)

CurrentRow("carid") = txtCarID.Text
CurrentRow.AcceptChanges()

Try
GetCommands()
da.Update(dtAutos)

Catch ex As Exception
MsgBox(ex.ToString)
Clipboard.SetDataObject(ex.ToString, True)
End Try
grdAutos.Refresh()

End Sub

Can anybody help? If you need clarification, post back, I'm very
confused as to why I can't read info straight from a textbox into a
db...
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


Nov 20 '05 #3
Hi Sparkle,

As Bill said the acceptchanges is a bad thing in your code however as well
what I write bellow.

Normaly the code I show you bellow will be enough, and probably is the
EndCurrentEdit your missing link (Because there is no row change, the data
is not entered in the table).

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)

'when there is only one table you can set this above somewhere global and do
this one time after a fill of the dataset.

BindingContext(dtAutos).EndCurrentEdit()

Try
da.Update(dtAutos)
Catch ex As Exception
MsgBox(ex.ToString)
Clipboard.SetDataObject(ex.ToString, True)
End Try
End Sub

I hope this helps?

Cor
Nov 20 '05 #4
Thanks for responding,

I know my post was confusing...

I CAN already get data into my db. Just not the ENTIRE row.

I'm missing carID or EmployeeID because the user isn't actually typing
them into the datagrid. I don't want that info to show in the data
grid.

The carID and EmployeeID on the form are from another datatable, so I
want to be able to programmatically say "whatever is currently in
txtCarID.text- go into the current row I've typed in the datagrid"

Is this possible?

I thought something like this would work, (but doesn't)
CurrentRow("carid") = txtCar.Text

Thanks, I hope you understand what I'm trying to do!
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #5
Hi Sparkle,

I think even simpler than you would believe.

http://msdn.microsoft.com/library/de...mputetopic.asp

You can set the table name before the columname in a way like this.
mytable.mycolumn

I hope this helps?

Copr
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stephan Steiner | last post by:
Hi I'm using several DataTables in my program which are updated periodically. At the same I have those tables bound to DataGrids in my GUI. So far I've been doing all the processing in the same...
6
by: Frank | last post by:
Hopefully this is the correct group for this message. My previous post to (I assume) a non-.net group was not welcomed. I have a form with 7 text boxes that are all bound to fields of a...
5
by: Rami | last post by:
Hey, I Tried to bind a DataGrid to an ArrayList, and had 2 problems: 1. The DataGrid shows the Length property of the items instead of their text - how can I change that? 2. After binding, I add...
16
by: stojilcoviz | last post by:
I've a datagrid whose datasource is an arraylist object. The arraylist holds many instances of a specific class. I've two questions about this: 1 - Is there a way by which I can obtain a...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
3
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather...
4
by: Rich | last post by:
Hello, I have a one datagrid that will be based on different datatables. One datatable may have 7 columns, another 15... With the tables that have more columns, I have been manually dragging...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
0
by: Jayant Solanki | last post by:
i have a problem with edit mode in datagrid. i have a calculation field in datagrid in which i want to do auto caluclation of "Total Fees" after updating the Amount and Rate. so how can i use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.