Application: ASP.NET
DB: SQL Serer 2000
IDE: VS 2003
My SQL server table consists of this
Status_id Status_Description
A Active
P Planned
I can't seem to figure out how to update my SQL server table. I have a select statement in a stored procedure that appears to be working correctly when I launch my ASP.net application. When I click my "Edit" button my datagrid goes into edit mode for the description field as desired; however, I need assistance coding the update pieces.
What do I put in my UpdateCommamnd block in the code-behind and how do I code my stored procedure?
I have researched numerous books and Internet resources and think I'm getting confused with the different methods to access different databases, specifically, stored procedures in SQL 2000.
Any help would be appreciated.
Thanks in advance,
Tim
Below is my code-behind
DB: SQL Serer 2000
IDE: VS 2003
My SQL server table consists of this
Status_id Status_Description
A Active
P Planned
I can't seem to figure out how to update my SQL server table. I have a select statement in a stored procedure that appears to be working correctly when I launch my ASP.net application. When I click my "Edit" button my datagrid goes into edit mode for the description field as desired; however, I need assistance coding the update pieces.
What do I put in my UpdateCommamnd block in the code-behind and how do I code my stored procedure?
I have researched numerous books and Internet resources and think I'm getting confused with the different methods to access different databases, specifically, stored procedures in SQL 2000.
Any help would be appreciated.
Thanks in advance,
Tim
Below is my code-behind
Code:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Data.Odbc
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents pnlStatusMaster As System.Web.UI.WebControls.Panel
Protected WithEvents dgStatusMaster As System.Web.UI.WebControls.DataGrid
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
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
If Not IsPostBack Then
Call LoadStatusMasterGrid()
End If
End Sub
Public Sub LoadStatusMasterGrid()
Dim connection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("sqlConn"))
connection.Open()
Try
Dim command As SqlCommand = _
New SqlCommand("usp_Select_Status_Master", connection)
Command.CommandType = CommandType.StoredProcedure
Dim adapter As SqlDataAdapter = New SqlDataAdapter(Command)
Dim table As DataTable = New DataTable
adapter.Fill(table)
dgStatusMaster.DataSource = table
dgStatusMaster.DataKeyField = "status_id"
dgStatusMaster.DataBind()
Catch ex As Exception
Console.WriteLine(ex.Message)
Throw
Finally
connection.Close()
End Try
End Sub
Private Sub dgStatusMaster_EditCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgStatusMaster.EditCommand
dgStatusMaster.EditItemIndex = e.Item.ItemIndex
dgStatusMaster.DataBind()
'Call LoadStatusMasterGrid()
End Sub
Private Sub dgStatusMaster_CancelCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgStatusMaster.CancelCommand
dgStatusMaster.EditItemIndex = -1
Call LoadStatusMasterGrid()
End Sub
Private Sub dgStatusMaster_UpdateCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgStatusMaster.UpdateCommand
End Sub
End Class