473,722 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update SQL Table Data using DataGrid

Hello All,

Is it possible to update Sql Table through DataGrid. I have a DataGrid
which is being populated through a stored procedure, all i wanted to do
is to update one field (FieldName-Authorised) which has a datatype bit
through DataGrid but not sure how to go about it. Any Ideas Guys on
this one, your help is greatly appreciated.

This is the procedure used to populate the datagrid, The primary key
for the table is EntryID which is displayed on the datagrid. I need to
update only one column based on the entryid, is that possible.

Private Sub FillData()
Dim username As String
username = lblUser.Text.Tr im
Try
Dim cmd2 As New SqlClient.SqlCo mmand
cmd2.CommandTex t = "c_sp_manager_a ccess"
cmd2.CommandTyp e = CommandType.Sto redProcedure
cmd2.Connection = SqlConnection1
cmd2.Parameters .Clear()
Dim myparam As New SqlClient.SqlPa rameter
myparam.Paramet erName = "@UserName"
myparam.Directi on = ParameterDirect ion.Input
myparam.SqlDbTy pe = SqlDbType.VarCh ar
myparam.Value = username
cmd2.Parameters .Add(myparam)
SqlDataAdapter1 .SelectCommand = cmd2
SqlDataAdapter1 .Fill(DataSet31 , "c_sp_manager_a ccess")
DataGrid1.DataB ind()

Catch ex As Exception
Dim debug As String = ex.Message
lblfeedback.Tex t = ex.Message
End Try
End Sub.

I have written a stored procedure to update the column, it takes the
following parameters

EntryID, Authorised(Valu e either True or False), EditedBy(String ).

Now how do i use this stored procedure in the datagrid to update my sql
table. Please advice.

Thanks in Advance, Shilpa.

Oct 29 '06 #1
1 6475
This is the Code i am using to update the data, the checkbox column in
the datagrid is template column. I am not sure do i add a button to the
form to get the below procedure executed how do i go about this one.
Can anyone help me here please.

Private Sub UpdateCommand_C lick(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DataGrid1.Updat eCommand
Dim DBCONN As New System.Data.Sql Client.SqlConne ction(CNString)
Dim CEID As TextBox = e.Item.Cells(0) .Controls(0)
Dim CAuth As TextBox = e.Item.Cells(9) .Controls(0)
Dim username As String
username = lblUser.Text.Tr im
Try
Dim cmd2 As New SqlClient.SqlCo mmand
cmd2.CommandTex t = "Update Table t_AbsenceEntry Set
Authorised='" & CAuth.Text & "' and EditedBy='" & username & "' Where
EntryID = " & CEID.Text
cmd2.CommandTyp e = CommandType.Sto redProcedure
cmd2.Connection = DBCONN
DBCONN.Open()
cmd2.ExecuteNon Query()
DataGrid1.EditI temIndex = -1
'BindData()
Dim rowsAffected As Integer = 1
If rowsAffected 0 Then
lblfeedback.Tex t = "Successful ly Update database!"
Else
lblfeedback.Tex t = "Fail to update Database!"
End If

Catch ex As Exception
lblfeedback.Tex t = ex.Message
End Try

End Sub

Sharon wrote:
Hello All,

Is it possible to update Sql Table through DataGrid. I have a DataGrid
which is being populated through a stored procedure, all i wanted to do
is to update one field (FieldName-Authorised) which has a datatype bit
through DataGrid but not sure how to go about it. Any Ideas Guys on
this one, your help is greatly appreciated.

This is the procedure used to populate the datagrid, The primary key
for the table is EntryID which is displayed on the datagrid. I need to
update only one column based on the entryid, is that possible.

Private Sub FillData()
Dim username As String
username = lblUser.Text.Tr im
Try
Dim cmd2 As New SqlClient.SqlCo mmand
cmd2.CommandTex t = "c_sp_manager_a ccess"
cmd2.CommandTyp e = CommandType.Sto redProcedure
cmd2.Connection = SqlConnection1
cmd2.Parameters .Clear()
Dim myparam As New SqlClient.SqlPa rameter
myparam.Paramet erName = "@UserName"
myparam.Directi on = ParameterDirect ion.Input
myparam.SqlDbTy pe = SqlDbType.VarCh ar
myparam.Value = username
cmd2.Parameters .Add(myparam)
SqlDataAdapter1 .SelectCommand = cmd2
SqlDataAdapter1 .Fill(DataSet31 , "c_sp_manager_a ccess")
DataGrid1.DataB ind()

Catch ex As Exception
Dim debug As String = ex.Message
lblfeedback.Tex t = ex.Message
End Try
End Sub.

I have written a stored procedure to update the column, it takes the
following parameters

EntryID, Authorised(Valu e either True or False), EditedBy(String ).

Now how do i use this stored procedure in the datagrid to update my sql
table. Please advice.

Thanks in Advance, Shilpa.
Oct 30 '06 #2

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

Similar topics

1
2994
by: Wing | last post by:
Hi all, I have created 2 tables in sql database and join these 2 tables before assign the result to the dataset, and display the result in datagrid. Everything is fine up to this point. The problem come up when I want to delete one of rows in datagrid and update the change to the corresponding table. The error msg show up "Dynamic SQL generation is not supported against multiple base tables."
3
2219
by: D. Shane Fowlkes | last post by:
I have a Datagrid which in theory, should allow you to edit and update the records. I've stripped my test page down so that it's only attempting to update one field - "description". Yet when I make the changes and click Update, it reverts back to the old value. I'm stumped! I've also checked the db table and it is infact not updating. I'm attempting to follow and example right out of ASP.NET Unleashed but not having much luck. Any...
2
2339
by: Ville Mattila | last post by:
Hi there, I will post my question to this group too bacause the .data group seems to be rather quiet. I've been playing with VB.NET and ADO for a week now and find the different data handling functions very easy and nice. Anyway, I'm afraid that I haven't understood the data binding things correct. I'm using MySQL Connector/.NET to access my database from the
6
1726
by: Brett | last post by:
Not sure what the problem is here... Trying to update from a datagrid to an access database using vb.net... Its not updating the database but Im not getting any errors... Here is my code... 'OleDbUpdateCommand1 Me.OleDbUpdateCommand1.CommandText = "UPDATE tblGifts SET gift = ?, name = ?, purchased = ? WHERE (autonum = ?) AND (gi" & _ "ft = ? OR ? IS NULL AND gift IS NULL) AND (name = ? OR ? IS NULL AND name IS NUL" & _
1
2023
by: mursyidatun ismail | last post by:
Dear all, database use: Ms Access. platform: .Net i'm trying to update a record/records in a table called t_doctors by clicking da edit link provided in the database. when i ran through da browsers and click update it gave me this error: Specified argument was out of the range of valid values. Parameter name:
2
1580
by: andrew.roberts | last post by:
This is my second post now on this subject has I seem to be getting no where and the problem is really starting to bug me now. I can get a datagrid into an editable state but then neither the Update or Cancel events seem to be firing and I am at a lost to explan why. My code is below, if any one can tell me what I am doing wrong then that would be excellent! using System; using System.Collections; using System.ComponentModel;
5
2596
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
13
2454
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever works best) to display a dropdown menu of fields populated from table tblInvoiceData. This control also includes a textbox which the user can input a value. These two columns are side by side and not in a vertical layout. The user then clicks on...
1
2296
by: geeteshss | last post by:
Dear all, actually i spent a whole month on the R&D of datagrid edit ,update,cancel events but recently my guide told me to make it user friendly because no user would like to go on searching rows and columns in a datagrid if there are number of rows and columns.so in my web page i have got two labels two textboxes and three buttons namely add update and delete so when i click on the add button the data is added to datagrid and also displayed...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
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
9238
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9088
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
5995
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
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
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
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
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.