Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET in Visual Studio2005 need help with SQLAdapter?

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
0
36
US
Using ASP.NET 2005
I was away from this project for months...
It is an event scheduling page to allow customers to select a date from the calendar, fill out name address etc and then it would email them and me notifying me of someone visiting and the details (all subject to approval later…)
I created a Stored Procedure and it sends data to add a record to the table. The page is supposed to send data to that Stored Procedure.
The problem now is I am getting an error at the bottom of the page
sqlAdapt and sqlCmd are not declared (noted in Red in the code below)
Can someone help me figure out what I need to do to add these back in?
I want to use most of my code and not re-write a bunch of stuff.

Here is my code:
Note some of it is removed to save space
Code:
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        'If Not Page.IsPostBack Then
        Dim CrLf As String = Chr(13) & Chr(10)
        'save to database

        Try
            ' create connection to db
            Dim cnBKTest As Data.SqlClient.SqlConnection
            ' build connection string to db
            cnBKTest = New Data.SqlClient.SqlConnection("Server=took this out for security")
            ' create command for sp
            Dim cmdTest As New Data.SqlClient.SqlCommand("sp_InsertIntoR2D2Events", cnBKTest)
            ' specify command type as stored procedure
            cmdTest.CommandType = Data.CommandType.StoredProcedure

            ' set up prameters for stored Proc
            cmdTest.Parameters.Add(New Data.SqlClient.SqlParameter("@TestParam", Data.SqlDbType.VarChar, 10))
            cmdTest.Parameters.Add(New Data.SqlClient.SqlParameter("@EventDate", Data.SqlDbType.SmallDateTime))
            cmdTest.Parameters.Add(New Data.SqlClient.SqlParameter("@EventStartTime", Data.SqlDbType.SmallDateTime))
            cmdTest.Parameters.Add(New Data.SqlClient.SqlParameter("@EventEndTime", Data.SqlDbType.SmallDateTime))
            cmdTest.Parameters.Add(New Data.SqlClient.SqlParameter("@ContactFName", Data.SqlDbType.NVarChar, 50))
            cmdTest.Parameters.Add(New Data.SqlClient.SqlParameter("@ContactLName", Data.SqlDbType.NVarChar, 50))
            cmdTest.Parameters.Add(New Data.SqlClient.SqlParameter("@ContactPhone", Data.SqlDbType.NVarChar, 50))
            cmdTest.Parameters.Add(New Data.SqlClient.SqlParameter("@LocationName", Data.SqlDbType.NVarChar, 50))

            'put form values into parameters for Stored Procedure
            cmdTest.Parameters("@EventDate").Value = Me.txtDateChoosen.Text
            cmdTest.Parameters("@EventStartTime").Value = Me.ddlStartTime.Text
            cmdTest.Parameters("@ContactFName").Value = Me.txtContactFName.Text
            cmdTest.Parameters("@ContactLName").Value = Me.txtContactLName.Text
            cmdTest.Parameters("@ContactPhone").Value = Me.txtContactPhone.Text
            cmdTest.Parameters("@LocationName").Value = Me.txtLocation.Text

            cnBKTest.Open()
            cmdTest.ExecuteNonQuery()
            cnBKTest.Close()

            Dim dt As New Data.DataTable()
            Dim myConnection As New Data.SqlClient.SqlConnection("Server=took this out for security")
            'Dim strSQL As String = "Insert into R2D2Events (EventDate, EventStartTime, EventEndTime, EventType, Company, ContactFName, ContactLName, ContactPhone, LocationName, LocationAddr1, LocationAddr2, LocationCity, LocationState, LocationZip,  Email,  Over18, SpecialInstructions) " & _
            '" VALUES (" & Me.txtDateChoosen.Text & ", " & Me.ddlStartTime.Text & ", " & Me.ddlEndTime.Text & ", " & Me.ddlEventType.Text & ", " & Me.txtCompany.Text & ", " & Me.txtContactFName.Text & ", " & Me.txtContactLName.Text & ", " & Me.txtContactPhone.Text & ", " & Me.txtLocation.Text & ", " & Me.txtLocationAddr1.Text & ", " & Me.txtLocationAddr2.Text & ", " & Me.txtLocationCity.Text & ", " & Me.txtLocationState.Text & ", " & Me.txtLocationZip.Text & ", " & Me.txtEmail.Text & ", " & Me.txtSpcialInstructions.Text & ", " & Me.chkIm18yearsold.Text & ")"
            Dim strSQL As String = "sp_InsertIntoR2D2Events"
            Dim myCommand As New Data.SqlClient.SqlCommand(strSQL, myConnection)
            myCommand.ExecuteNonQuery()

            sqlAdapt.SelectCommand = sqlCmd [COLOR=red] <both are missing [/color]
        Catch ex As Exception
            lblErrorStatus.Text = ex.ToString()
        End Try


DougP
[r2d2] < I Built one
 
Should the question not be posted to asp.net?

By a quick scan through the script, it seems strange
[0] myConnection seems nowhere Open(), so I wonder the last ExecuteNonQuery() works out.
[1] sqlAdapt and sqlCmd seem nowhere defined, so it is natural they error out? They would be initiated something like this.
[tt]
Dim sqlAdapt As Data.SqlClient.SqlAdapter = New Data.SqlClient.SqlAdapter()
Dim sqlCmd As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand("select * from R2D2Events where Company='xyz'") 'or something more pertinent
sqlAdapt.SelectCommand = sqlCmd
'etc...
[/tt]
[2] In any case, asp.net should have the proper audience to help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top