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

Code to update the table

Please excuse my ignorance, but I am trying to teach myself .Net
without a lot of help. At this point I have created a page with a few
text boxes and combo boxes that I am using as an example.

The page displays nicely with the Requestor, DivMgr, ChgType,
Description fields.

What I would like to do at this point is create a Save button (at
bottom ref: Button1_Click) that, when clicked, inserts the data to the
table.

Can a .Net guru help with this one?
Thanks for the help in advance.

'************************************************* ***********
Imports System.Data.SqlClient

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()
Dim configurationAppSettings As
System.Configuration.AppSettingsReader = New
System.Configuration.AppSettingsReader
Me.conn = New System.Data.SqlClient.SqlConnection
'
'conn
'
Me.conn.ConnectionString =
CType(configurationAppSettings.GetValue("conn.Conn ectionString",
GetType(System.String)), String)

End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents conn As System.Data.SqlClient.SqlConnection
Protected WithEvents ddlRequestor As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents ddlDivMgr As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label5 As System.Web.UI.WebControls.Label
Protected WithEvents tbxDescription As
System.Web.UI.WebControls.TextBox
Protected WithEvents tbxChangeName As
System.Web.UI.WebControls.TextBox
Protected WithEvents Label6 As System.Web.UI.WebControls.Label
Protected WithEvents ddlChangeType As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

'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
'Put user code to initialize the page here
Dim query As String
Dim ds As New DataSet
query = "select names from requestor order by names"
Dim da As New SqlDataAdapter(query, conn)
da.Fill(ds, "Requestor")
ddlRequestor.DataSource = ds
ddlRequestor.DataMember = "Requestor"
ddlRequestor.DataTextField = "names"
ddlRequestor.DataBind()

query = "select DivMgr from DivMgr order by DivMgr"
Dim daDivMgr As New SqlDataAdapter(query, conn)
daDivMgr.Fill(ds, "DivMgr")
ddlDivMgr.DataSource = ds
ddlDivMgr.DataMember = "DivMgr"
ddlDivMgr.DataTextField = "DivMgr"
ddlDivMgr.DataBind()

query = "select Type from ChgType order by Type"
Dim daChangeType As New SqlDataAdapter(query, conn)
daChangeType.Fill(ds, "ChgType")
ddlChangeType.DataSource = ds
ddlChangeType.DataMember = "ChgType"
ddlChangeType.DataTextField = "Type"
ddlChangeType.DataBind()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'How do I insert the values above?
End Sub
End Class

Nov 21 '05 #1
4 1328
The following KB article may be of some assistance, depending on your exact
circumstances.

http://support.microsoft.com/default...b;en-us;301248

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.
"robboll" <ro*****@hotmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Please excuse my ignorance, but I am trying to teach myself .Net
without a lot of help. At this point I have created a page with a few
text boxes and combo boxes that I am using as an example.

The page displays nicely with the Requestor, DivMgr, ChgType,
Description fields.

What I would like to do at this point is create a Save button (at
bottom ref: Button1_Click) that, when clicked, inserts the data to the
table.

Can a .Net guru help with this one?
Thanks for the help in advance.

'************************************************* ***********
Imports System.Data.SqlClient

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()
Dim configurationAppSettings As
System.Configuration.AppSettingsReader = New
System.Configuration.AppSettingsReader
Me.conn = New System.Data.SqlClient.SqlConnection
'
'conn
'
Me.conn.ConnectionString =
CType(configurationAppSettings.GetValue("conn.Conn ectionString",
GetType(System.String)), String)

End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents conn As System.Data.SqlClient.SqlConnection
Protected WithEvents ddlRequestor As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents ddlDivMgr As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label5 As System.Web.UI.WebControls.Label
Protected WithEvents tbxDescription As
System.Web.UI.WebControls.TextBox
Protected WithEvents tbxChangeName As
System.Web.UI.WebControls.TextBox
Protected WithEvents Label6 As System.Web.UI.WebControls.Label
Protected WithEvents ddlChangeType As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

'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
'Put user code to initialize the page here
Dim query As String
Dim ds As New DataSet
query = "select names from requestor order by names"
Dim da As New SqlDataAdapter(query, conn)
da.Fill(ds, "Requestor")
ddlRequestor.DataSource = ds
ddlRequestor.DataMember = "Requestor"
ddlRequestor.DataTextField = "names"
ddlRequestor.DataBind()

query = "select DivMgr from DivMgr order by DivMgr"
Dim daDivMgr As New SqlDataAdapter(query, conn)
daDivMgr.Fill(ds, "DivMgr")
ddlDivMgr.DataSource = ds
ddlDivMgr.DataMember = "DivMgr"
ddlDivMgr.DataTextField = "DivMgr"
ddlDivMgr.DataBind()

query = "select Type from ChgType order by Type"
Dim daChangeType As New SqlDataAdapter(query, conn)
daChangeType.Fill(ds, "ChgType")
ddlChangeType.DataSource = ds
ddlChangeType.DataMember = "ChgType"
ddlChangeType.DataTextField = "Type"
ddlChangeType.DataBind()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'How do I insert the values above?
End Sub
End Class
Nov 21 '05 #2
Robboll,

In my opinion does it go to far if we try to complete the most difficult
part of your program.

However you are talking about comboboxes while you are using dropdownboxes
the combobox is a control from a winform and not from a webform.

It is therefore normal to assume than that you use a winform and not a
webform application (what I could only see in your code).

While when not tell in this newsgroup a winform is default.

Probably therefore you got from David a sample for a winform application.

There is a big different however probably you can use it, if you keep
remembering you that a weppage is not persistent. That means that you have
to save the data when you end your program (post the page) in a session
item.

response.session.item("ds") = mydataset

When it is posted back you can load the dataset than again.

Have a look for that for that session and IsPostBack on MSDN.

I hope this helps,

Cor
Nov 21 '05 #3
As I said -- "excuse my ignorance" I am finally getting involved with
..Net and at this juncture a combobox is a dropdown is a "thingy that
you click on to display a list of values", etc. But I'm getting there.
The vernacular comes next. But thanks for the clarification.

Cor Ligthert wrote:
Robboll,

In my opinion does it go to far if we try to complete the most difficult
part of your program.

However you are talking about comboboxes while you are using dropdownboxes
the combobox is a control from a winform and not from a webform.

It is therefore normal to assume than that you use a winform and not a
webform application (what I could only see in your code).

While when not tell in this newsgroup a winform is default.

Probably therefore you got from David a sample for a winform application.

There is a big different however probably you can use it, if you keep
remembering you that a weppage is not persistent. That means that you have
to save the data when you end your program (post the page) in a session
item.

response.session.item("ds") = mydataset

When it is posted back you can load the dataset than again.

Have a look for that for that session and IsPostBack on MSDN.

I hope this helps,

Cor


Nov 21 '05 #4
Thanks for the tip. I should be able to do something with it.

RBollinger

Nov 21 '05 #5

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

Similar topics

4
by: jason | last post by:
Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go
6
by: Jeff Kowalczyk | last post by:
I need to adapt this an update statement to a general form that will iterate over multiple orderids for a given customerinvoiceid. My first concern is a form that will work for a given orderid,...
1
by: Neo Geshel | last post by:
I am having conflicting results with two pieces of identical code. One is an insert, the other is an update to a db. The first code, which works, is this: Sub Add3_Click(sender As Object, e As...
3
by: equalive | last post by:
Hi guys, I'm having problem locking a table in Ms Access using VB6 code. Actually I have 3 tables. Assume table names is A, B, C. Following is the process. 1. Open table A and update table...
3
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
2
by: travhale | last post by:
in a new project using .net 2005, c#. getting err message "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." source RDBMS is oracle 8i. I add a new...
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
0
by: JimN1 | last post by:
Error: Update requires a valid UpdateCommand when passed DataRow collection with modified rows. This is a continuation of my previous table element update question. I am now getting the above...
0
by: emalcolm_FLA | last post by:
Hello and TIA for any help with this non profit Christmas assistance project. I have an applicant (app history) and child (child history) tables (4 total). I need to grab the next available (in...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
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...

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.