473,773 Members | 2,286 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating Data from a dataGrid

Hey, I have never used a datagrid/dataset/adaptor/table method for updating
data, I have always used direct updates to the database so ADO is quite new
to me.

I have a datagrid and I change a value in one of the fields.
I hit save and the following code runs...

Dim da As SqlClient.SqlDa taAdapter = New SqlClient.SqlDa taAdapter("Sele ct *
from MISRE_Threshold ", cn)
da.Update(dsThr eshold, "MISRE_Threshol d")
my code to populate the datagrid is as below, what am i missing to actually
update the data in the database......

Private Sub Thresholds_Load (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

UserName.Text = dbProps.MyUserN ame
Password.Text = dbProps.MyPassw ord
Database.Text = dbProps.MyDatab ase
Server.Text = dbProps.MyServe r

Try
cn = New SqlClient.SqlCo nnection("user id=" & UserName.Text &
";password= " & Password.Text & ";database= " & Database.Text & ";server=" &
Server.Text)
cn.Open()
cmdSelect.Conne ction = cn

Dim da As SqlClient.SqlDa taAdapter = New
SqlClient.SqlDa taAdapter("Sele ct * from MISRE_Threshold ", cn)
'Dim dsThreshold As DataSet = New DataSet

' fill dataset
da.Fill(dsThres hold, "MISRE_Threshol d")

'Attach DataSet to DataGrid
dgThreshold.Dat aSource = dsThreshold.Def aultViewManager
Dim dt As New DataTable
dt.CaseSensitiv e = False
dt = dsThreshold.Tab les("MISRE_Thre shold")

Catch ex As Exception
MessageBox.Show ("Error: Could not establish database connection")
End Try

End Sub
May 12 '06 #1
2 1329
rj
hi,

i dont know about your code, but if you're using visual studio 2002 or
later, you can use the data form wizard. this will add the buttons to
your form and all you have to do is sort out the layout.
To go there click 'new item' > select dataform wizard and follow the
wizard.
Its a really easy way of doing simple data forms.

hope it helps..

May 12 '06 #2
Thanks but I am trying to write code that will update the dataset (and
database) with any changes the user makes to the datagrid. I tried the
DataAdaptor configuration wizard but it doesn't work.

How do I overcome this issue?

May 12 '06 #3

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

Similar topics

0
1303
by: cwbp17 | last post by:
Have two tables that have a FK relationship on ID column. Have one datagrid that displays all of the columns of both tables. What's the best approach on updating a row from the datagrid back to the database? I've used the following code for the DataGird1_UpdateCommand Option1
3
1801
by: Jon Agiato | last post by:
Hi, I am trying to use a data grid in a web application in which I have three tiers. The DataGrid is not set up to a data source, or a data adapter, so everytime I make a change I send the cell information to another object which forms an SQL query and makes the query to the DB (actually to a DBFacade object). In any case, please see the code I have listed below for my update DataGrid event. With this code, the DB is updated using the old...
5
2039
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 one row, all of them were updated so i immediatelly figured out that i have to include the id of every entry in the update statement. This is where the problem is raised. My database is an Access database. The table i am updating contains a Date...
9
1593
by: A P | last post by:
Hi! I have created a sample datagrid that can update data on a database. Please help me solve the problem, I have attached both aspx and code behind (aspx.vb): ______________________ datagrid.aspx
1
1337
by: Geraldine Hobley | last post by:
hello, I have put thisup b4, but I think that people have misunderstood the problem, so I will make it clearer. I have a problem updating a dataset that is bound to a datagrid. The code that I use to set up the grid dgsimple to the dataset Mydataset and the table "Orders" is as below (see bottom of page) My problem is that I can change data in the datagrid on the first row of the grid and the changes will be immediately written away,...
10
5682
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1) DsStudentCourse1.AcceptChanges() i'm also wondering because w/ out AcceptChanges the data is still save into the database and it is now faster.
2
1675
by: Greg | last post by:
I'm using the Framework 1.1, so I don't have access to the new DataGridView object. What I'm wondering is, is there a really simple way to bind a plain datagrid to a database in such a way that changes made to cells in the datagrid call an update on the corresoonding data within a database? I've looked in vain for a really simple way to do this with minimal coding, but I'm coming to the conclusion that I will have to trap the events of...
2
4375
by: toddw607 | last post by:
Hi Everyone! I have a ASP.NET webform that brings data in from SQL Server 2000 and displays it on a page. I want to update the webpage while in IE using the following code: <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="System.Data.OleDb" %> <html>
2
3321
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the CurrentChanged event of the BindingSource of the combobox to update the textbox. When selecting an item in the combobox or when selecting a row in the grid, it is updating the textbox correctly. The problem is when I apply a filter in the grid, and then...
0
9621
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10264
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.