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

SqlDataAdapter1.update for datagrid1 does not work

I cannot make my update command work for a datagrid:

Public Class subcatinsert
Inherits System.Web.UI.Page
Protected WithEvents SqlCon As System.Data.SqlClient.SqlConnection
Protected WithEvents SqlSelectCommand1 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlInsertCommand1 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlUpdateCommand1 As
System.Data.SqlClient.SqlCommand
Protected WithEvents AdapSubCat As
System.Data.SqlClient.SqlDataAdapter
Protected WithEvents AdapCatMaster As
System.Data.SqlClient.SqlDataAdapter
Protected WithEvents SqlSelectCommand2 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlInsertCommand2 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlUpdateCommand2 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlDeleteCommand2 As
System.Data.SqlClient.SqlCommand
Protected WithEvents GL_DS_SubCatCatMaster1 As
_packpay.GL_DS_SubCatCatMaster
Protected WithEvents DataGrid1 As
System.Web.UI.WebControls.DataGrid
Protected WithEvents SqlDeleteCommand1 As
System.Data.SqlClient.SqlCommand

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()Private Sub
InitializeComponent()
Me.SqlCon = New System.Data.SqlClient.SqlConnection
Me.AdapSubCat = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
Me.AdapCatMaster = New System.Data.SqlClient.SqlDataAdapter
Me.SqlDeleteCommand2 = New System.Data.SqlClient.SqlCommand
Me.SqlInsertCommand2 = New System.Data.SqlClient.SqlCommand
Me.SqlSelectCommand2 = New System.Data.SqlClient.SqlCommand
Me.SqlUpdateCommand2 = New System.Data.SqlClient.SqlCommand
Me.GL_DS_SubCatCatMaster1 = New _packpay.GL_DS_SubCatCatMaster
CType(Me.GL_DS_SubCatCatMaster1,
System.ComponentModel.ISupportInitialize).BeginIni t()
'
'SqlCon
'
Me.SqlCon.ConnectionString = "workstation id=HERE GES THE
LOGIN"
'
'AdapSubCat
'
Me.AdapSubCat.DeleteCommand = Me.SqlDeleteCommand1
Me.AdapSubCat.InsertCommand = Me.SqlInsertCommand1
Me.AdapSubCat.SelectCommand = Me.SqlSelectCommand1
Me.AdapSubCat.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "SubCat", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("SubCatId", "SubCatId"), New
System.Data.Common.DataColumnMapping("CatMasterId" , "CatMasterId"),
New System.Data.Common.DataColumnMapping("SubCatStatus ",
"SubCatStatus"), New
System.Data.Common.DataColumnMapping("SubCatDesc", "SubCatDesc")})})
Me.AdapSubCat.UpdateCommand = Me.SqlUpdateCommand1
'
'SqlDeleteCommand1
'
Me.SqlDeleteCommand1.CommandText = "DELETE FROM SubCat WHERE
(SubCatId = @Original_SubCatId) AND (CatMasterId = @" & _
"Original_CatMasterId OR @Original_CatMasterId IS NULL AND
CatMasterId IS NULL) A" & _
"ND (SubCatDesc = @Original_SubCatDesc OR @Original_SubCatDesc
IS NULL AND SubCat" & _
"Desc IS NULL) AND (SubCatStatus = @Original_SubCatStatus OR
@Original_SubCatStat" & _
"us IS NULL AND SubCatStatus IS NULL)"
Me.SqlDeleteCommand1.Connection = Me.SqlCon
Me.SqlDeleteCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_SubC atId",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "SubCatId",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_CatM asterId",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "CatMasterId",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_SubC atDesc",
System.Data.SqlDbType.VarChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "SubCatDesc", System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_SubC atStatus",
System.Data.SqlDbType.TinyInt, 1,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "SubCatStatus", System.Data.DataRowVersion.Original, Nothing))
'
'SqlInsertCommand1
'
Me.SqlInsertCommand1.CommandText = "INSERT INTO
SubCat(CatMasterId, SubCatStatus, SubCatDesc) VALUES (@CatMasterI" & _
"d, @SubCatStatus, @SubCatDesc); SELECT SubCatId, CatMasterId,
SubCatStatus, SubC" & _
"atDesc FROM SubCat WHERE (SubCatId = @@IDENTITY)"
Me.SqlInsertCommand1.Connection = Me.SqlCon
Me.SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CatMasterId",
System.Data.SqlDbType.Int, 4, "CatMasterId"))
Me.SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@SubCatStatus" ,
System.Data.SqlDbType.TinyInt, 1, "SubCatStatus"))
Me.SqlInsertCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@SubCatDesc",
System.Data.SqlDbType.VarChar, 150, "SubCatDesc"))
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT SubCatId,
CatMasterId, SubCatStatus, SubCatDesc FROM SubCat"
Me.SqlSelectCommand1.Connection = Me.SqlCon
'
'SqlUpdateCommand1
'
Me.SqlUpdateCommand1.CommandText = "UPDATE SubCat SET
CatMasterId = @CatMasterId, SubCatStatus = @SubCatStatus, S" & _
"ubCatDesc = @SubCatDesc WHERE (SubCatId = @Original_SubCatId)
AND (CatMasterId =" & _
" @Original_CatMasterId OR @Original_CatMasterId IS NULL AND
CatMasterId IS NULL)" & _
" AND (SubCatDesc = @Original_SubCatDesc OR
@Original_SubCatDesc IS NULL AND SubC" & _
"atDesc IS NULL) AND (SubCatStatus = @Original_SubCatStatus OR
@Original_SubCatSt" & _
"atus IS NULL AND SubCatStatus IS NULL); SELECT SubCatId,
CatMasterId, SubCatStat" & _
"us, SubCatDesc FROM SubCat WHERE (SubCatId = @SubCatId)"
Me.SqlUpdateCommand1.Connection = Me.SqlCon
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CatMasterId",
System.Data.SqlDbType.Int, 4, "CatMasterId"))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@SubCatStatus" ,
System.Data.SqlDbType.TinyInt, 1, "SubCatStatus"))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@SubCatDesc",
System.Data.SqlDbType.VarChar, 150, "SubCatDesc"))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_SubC atId",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "SubCatId",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_CatM asterId",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "CatMasterId",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_SubC atDesc",
System.Data.SqlDbType.VarChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "SubCatDesc", System.Data.DataRowVersion.Original, Nothing))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_SubC atStatus",
System.Data.SqlDbType.TinyInt, 1,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "SubCatStatus", System.Data.DataRowVersion.Original, Nothing))
Me.SqlUpdateCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@SubCatId",
System.Data.SqlDbType.Int, 4, "SubCatId"))
'
'AdapCatMaster
'
Me.AdapCatMaster.DeleteCommand = Me.SqlDeleteCommand2
Me.AdapCatMaster.InsertCommand = Me.SqlInsertCommand2
Me.AdapCatMaster.SelectCommand = Me.SqlSelectCommand2
Me.AdapCatMaster.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "CatMaster", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("CatMasterId" , "CatMasterId"),
New System.Data.Common.DataColumnMapping("CatMasterSta tus",
"CatMasterStatus"), New
System.Data.Common.DataColumnMapping("CatMasterDes c",
"CatMasterDesc")})})
Me.AdapCatMaster.UpdateCommand = Me.SqlUpdateCommand2
'
'SqlDeleteCommand2
'
Me.SqlDeleteCommand2.CommandText = "DELETE FROM CatMaster
WHERE (CatMasterId = @Original_CatMasterId) AND (CatMas" & _
"terDesc = @Original_CatMasterDesc OR @Original_CatMasterDesc
IS NULL AND CatMast" & _
"erDesc IS NULL) AND (CatMasterStatus =
@Original_CatMasterStatus OR @Original_Ca" & _
"tMasterStatus IS NULL AND CatMasterStatus IS NULL)"
Me.SqlDeleteCommand2.Connection = Me.SqlCon
Me.SqlDeleteCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_CatM asterId",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "CatMasterId",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_CatM asterDesc",
System.Data.SqlDbType.VarChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "CatMasterDesc", System.Data.DataRowVersion.Original, Nothing))
Me.SqlDeleteCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_CatM asterStatus",
System.Data.SqlDbType.TinyInt, 1,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "CatMasterStatus", System.Data.DataRowVersion.Original,
Nothing))
'
'SqlInsertCommand2
'
Me.SqlInsertCommand2.CommandText = "INSERT INTO
CatMaster(CatMasterStatus, CatMasterDesc) VALUES (@CatMasterStatu" & _
"s, @CatMasterDesc); SELECT CatMasterId, CatMasterStatus,
CatMasterDesc FROM " & _
"CatMaster WHERE (CatMasterId = @@IDENTITY)"
Me.SqlInsertCommand2.Connection = Me.SqlCon
Me.SqlInsertCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CatMasterStat us",
System.Data.SqlDbType.TinyInt, 1, "CatMasterStatus"))
Me.SqlInsertCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CatMasterDesc ",
System.Data.SqlDbType.VarChar, 150, "CatMasterDesc"))
'
'SqlSelectCommand2
'
Me.SqlSelectCommand2.CommandText = "SELECT CatMasterId,
CatMasterStatus, CatMasterDesc FROM CatMaster"
Me.SqlSelectCommand2.Connection = Me.SqlCon
'
'SqlUpdateCommand2
'
Me.SqlUpdateCommand2.CommandText = "UPDATE CatMaster SET
CatMasterStatus = @CatMasterStatus, CatMasterDesc = @Cat" & _
"MasterDesc WHERE (CatMasterId = @Original_CatMasterId) AND
(CatMasterDesc = @Ori" & _
"ginal_CatMasterDesc OR @Original_CatMasterDesc IS NULL AND
CatMasterDesc IS NULL" & _
") AND (CatMasterStatus = @Original_CatMasterStatus OR
@Original_CatMasterStatus " & _
"IS NULL AND CatMasterStatus IS NULL); SELECT CatMasterId,
CatMasterStatus, CatMa" & _
"sterDesc FROM CatMaster WHERE (CatMasterId = @CatMasterId)"
Me.SqlUpdateCommand2.Connection = Me.SqlCon
Me.SqlUpdateCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CatMasterStat us",
System.Data.SqlDbType.TinyInt, 1, "CatMasterStatus"))
Me.SqlUpdateCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CatMasterDesc ",
System.Data.SqlDbType.VarChar, 150, "CatMasterDesc"))
Me.SqlUpdateCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_CatM asterId",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "CatMasterId",
System.Data.DataRowVersion.Original, Nothing))
Me.SqlUpdateCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_CatM asterDesc",
System.Data.SqlDbType.VarChar, 150,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "CatMasterDesc", System.Data.DataRowVersion.Original, Nothing))
Me.SqlUpdateCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@Original_CatM asterStatus",
System.Data.SqlDbType.TinyInt, 1,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "CatMasterStatus", System.Data.DataRowVersion.Original,
Nothing))
Me.SqlUpdateCommand2.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CatMasterId",
System.Data.SqlDbType.Int, 4, "CatMasterId"))
'
'GL_DS_SubCatCatMaster1
'
Me.GL_DS_SubCatCatMaster1.DataSetName =
"GL_DS_SubCatCatMaster"
Me.GL_DS_SubCatCatMaster1.Locale = New
System.Globalization.CultureInfo("en-US")
Me.GL_DS_SubCatCatMaster1.Namespace = "http://192.168.1.214/
admin/dataset/GL_DS_SubCatCatMaster.xsd"
CType(Me.GL_DS_SubCatCatMaster1,
System.ComponentModel.ISupportInitialize).EndInit( )

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'let get it on
Dim DBString As New dls
Dim GetDatabaseString As String
SqlCon.ConnectionString =
DBString.GetLongString("GetDatabaseString")
SqlCon.Open()

Rebind()

End Sub
Private Sub Rebind()

AdapCatMaster.Fill(GL_DS_SubCatCatMaster1, "CatMaster")
AdapSubCat.Fill(GL_DS_SubCatCatMaster1, "SubCat")
DataGrid1.DataBind()

End Sub

Public Function BindJob(ByVal o As Object) As String

Dim drv As DataRowView = o

Dim dr As GL_DS_SubCatCatMaster.SubCatRow = drv.Row

'Dim dp As Employees.jobsRow = dr.GetParentRow("jobsemployee")
'Return dp.job_desc
' Alternatively, since this is strongly typed:
Return dr.CatMasterRow.CatMasterDesc

End Function

Public Sub EditCommand(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

DataGrid1.EditItemIndex = e.Item.ItemIndex

Rebind()

End Sub

Public Sub CancelCommand(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

DataGrid1.EditItemIndex = -1

Rebind()

End Sub

Public Sub ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)

Dim lit As ListItemType = e.Item.ItemType

If lit = ListItemType.EditItem Then

Dim ddlCatMaster As DropDownList
ddlCatMaster = e.Item.FindControl("ddlCatMaster")

Dim drv As DataRowView = e.Item.DataItem

If Not drv Is Nothing Then

ddlCatMaster.Items.FindByValue(drv("CatMasterId")) .Selected = True
End If

End If

End Sub

Public Sub UpdateCommand(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

'Rebind()

'Get reference to current row
Dim dr As GL_DS_SubCatCatMaster.SubCatRow =
GL_DS_SubCatCatMaster1.SubCat.Item(e.Item.DataSetI ndex)

Dim ddlCatMaster As DropDownList
ddlCatMaster = e.Item.FindControl("ddlCatMaster")

dr.CatMasterId = ddlCatMaster.SelectedItem.Value

' Update
AdapSubCat.Update(GL_DS_SubCatCatMaster1, "SubCat")
GL_DS_SubCatCatMaster1.AcceptChanges()

DataGrid1.EditItemIndex = -1

Rebind()

End Sub

End Class

Mar 27 '07 #1
1 1727
I found that the update command works but the value on the drop down
is the same as the original value.

Mar 28 '07 #2

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

Similar topics

5
by: Google Jenny | last post by:
Hi. My colleague and I have followed the procedure to populate a form with data from a database, using this code: private void bindGrid() { sqlConnection1.Open();...
1
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...
3
by: Russ Green | last post by:
I am currently learning asp.net (vb) with Web Matrix. I am building an intranet page that will have an editable datagrid on it. I have got the datagrid to populate OK but I cannot get the Update...
2
by: JIM.H. | last post by:
Hello, I have SqlDataAdapter1 and DataSet11 in my asp.net application and I am using then in many function to select and update the table. Is there any way to restrict the query of SqlDataAdapter1...
4
by: Jonathan Upright | last post by:
Greetings to anyone who can help: I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable DataGrid" at the project selector screen. As you may know, it defaults to the Microsoft...
2
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...
5
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
0
by: Patty05 | last post by:
I have a datagrid on a form that update properly when form loads. When the program runs and I type in/add a new row in the datagrid, it does not save the changes. Any help would be greatly...
4
by: Stephen Plotnick | last post by:
In a data grid using Access as the data source.. The da.update is failing with "object reference not set to an instance of anobject" It looks like everything is ok and I was wondering if there...
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
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...
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
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...
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
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...

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.