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

Button Click Inserts Sql Data From Web Form

1
Hi Folks,

I'm completely new to this stuff so bear with me. And if this isn't the correct forum, just let me know which this should be in and I'll post it there. VB and VWD are both .NET apps so I figure this is the right place.

I'm using VWD and want to have a form, the contents of which get inserted into a sql db. I was able to find the following code that I tweaked a bit to get working in a VB program but cannot figure out how to adjust it to work on a web page. I'm still finding and watching videos and reading books I've downloaded and I'm learning a lot...but the answer to this seems to be evading me. I can use VWD's Gridview, etc. tools to populate a table but I would like to be able to make a custom form with a button to do the job instead.

So here's the VB code I found and was able to teach myself how to use....and actually got it working in a program....

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
  2.  
  3.         Dim SQLtext As String
  4.         Dim myCon As New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Documents and Settings\Bob\My Documents\Visual Studio 2005\Projects\Addresses\Addresses\FirstDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
  5.  
  6.         SQLtext = "INSERT INTO Addresses (FirstName, LastName, StreetAddress, City, Phone) VALUES(@txtFirstName, @txtLastName, @txtStreetAddress, @txtCity, @txtPhone)"
  7.  
  8.         Dim myCom As New SqlClient.SqlCommand(SQLtext, myCon)
  9.  
  10.         Dim val1 = Me.txtFirstName.Text
  11.         Dim val2 = Me.txtLastName.Text
  12.         Dim val3 = Me.txtStreetAddress.Text
  13.         Dim val4 = Me.txtCity.Text
  14.         Dim val5 = Me.txtPhone.Text()
  15.  
  16.  
  17.         myCom.Parameters.Add(New SqlClient.SqlParameter("@txtFirstName", SqlDbType.VarChar)).Value = val1
  18.         myCom.Parameters.Add(New SqlClient.SqlParameter("@txtLastName", SqlDbType.VarChar)).Value = val2
  19.         myCom.Parameters.Add(New SqlClient.SqlParameter("@txtStreetAddress", SqlDbType.VarChar)).Value = val3
  20.         myCom.Parameters.Add(New SqlClient.SqlParameter("@txtCity", SqlDbType.VarChar)).Value = val4
  21.         myCom.Parameters.Add(New SqlClient.SqlParameter("@txtPhone", SqlDbType.VarChar)).Value = val5
  22.  
  23.     End Sub
  24.  
  25.  
Thanks much,
Bob
Nov 2 '07 #1
0 774

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: piperzen | last post by:
Hi, I'm developing a set of language learning exercises for http://www.yale.edu/swahili , and we've run into a javascript question that the programmer doesn't know how to tackle (we mostly work...
2
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New...
7
by: Miguel Dias Moura | last post by:
Hello, I am working in ASP.net / VB with Access Database. i have a Multipage in my web site with the Submit button as the last button. When the Submit button is pressed i want the form...
0
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is...
1
by: Klaus Jensen | last post by:
Hi! This has been annoying me all day, and I can't get it to work It is really driving me nuts! Basicly this simple webapp created to illustrate my problem, renders five buttons, and adds a...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
1
by: Stephen D Cook | last post by:
What I am trying to do is have a set of option buttons which are required to click one. If the person doesn't click any before insert, they get an error. If they do click one, it inserts into the...
5
by: Neo Geshel | last post by:
Greetings. I am in a very big pickle. I am trying to add page content - as well as a submit button - programatically to a web form that is supposed to submit to DB and then refresh. That...
11
by: cindy | last post by:
I have a form, has javascript registered so a modal pops up. Button click will close form. Now I need to do an update with modal form data before it closes. I can put a second button and register...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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,...
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.