Inserting Records Question?
Hello
Im trying to insert data into 5 fields in a database. The problem Im having is the first 3 fields keep getting null values in the database. In other words its inserting data into the last 2 fields but not into the first 3. Its just leaving them blank.
Can anyone help me with problem? Here is my code.
Public area(3), phone(3), e1, e2 As String
#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 txtMsg As System.Web.UI.WebControls.TextBox
Protected WithEvents btnChange As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents btnRegister 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
If Not IsPostBack Then
messageForm = CType(Context.Handler, WebForm1)
'Dim area(3), phone(3), e1, e2 As String
Dim i As Integer
Dim theLine As String
Response.Buffer = True
area(1) = Request.Form("txtArea1") : phone(1) = Request.Form("txtPhone1")
area(2) = Request.Form("txtArea2") : phone(2) = Request.Form("txtPhone2")
area(3) = Request.Form("txtArea3") : phone(3) = Request.Form("txtPhone3")
e1 = Request.Form("txtEmail1")
e2 = Request.Form("txtEmail2")
'create session variables
Session("a1") = area(1) : Session("p1") = phone(1)
Session("a2") = area(2) : Session("p2") = phone(2)
Session("a3") = area(3) : Session("p3") = phone(3)
Session("e1") = e1
'Data validation
'Loop through area and phone array checking for invalid data
txtMsg.Text = ""
For i = 1 To 3
If area(i) <> "" Or phone(i) <> "" Then
If Not IsNumeric(area(i)) Or Not IsNumeric(phone(i)) Then
txtMsg.Text = "Invalid Data." & vbCrLf & "Please go to previous page and re-enter."
Exit Sub
End If
End If
Next
'Checking if either email text boxes are blank
If (e1 = "") Or (e2 = "") Then
txtMsg.Text = "Email addresses are not fully completed." & vbCrLf & "Please go to previous page and re-enter."
Exit Sub
End If
'Reset counter variable to 0 and populate Msg text box if email addresses match
i = 0
If e1 = e2 Then
For i = 1 To 3
If phone(i) <> "" Then
theLine &= " Area: " & area(i) & " Phone: " & phone(i).Insert(3, "-") & vbCrLf
End If
Next
theLine &= " Email: " & e1
txtMsg.Text = theLine
Else
txtMsg.Text = "Email addresses are not the same." & vbCrLf & "Please go to previous page and re-enter."
End If
End If
End Sub
Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
Dim myCNN As New ADODB.Connection
Dim mySQL As String
Dim counter As Integer
Dim registerDate As DateTime = Today
Dim expireDate As DateTime = Today.AddYears(5)
myCNN.Open("DSN=MyDoNotCall")
counter = 0
For counter = 1 To 3
mySQL = "Insert INTO Master(PatronEmail,AreaCode,PhoneNumber,Registrati onDate,ExpirationDate)"
mySQL = mySQL & "Values('" & e1 & "','" & area(counter) & "','" & phone(counter) & "','" & registerDate & "','" & expireDate & "')"
myCNN.Execute(mySQL)
Next
myCNN.Close()
myCNN = Nothing
End Sub
All the help will be greatly appreciated.
Eric
|