mardi 30 mai 2017

ASP.NET (VB) Trying set DB connection from web.config

I have a web form project to update columns in an Microsoft SQL 2012 database table. When I "hard code" the connection info for my SqlConnection everything works fine. However if I try going the ConfigurationManager.ConnectionStrings route I get a keyword 'id' not supported. I have included the Imports.System.Configuration code into my project. Below is the Sub where I am running into the issue

 Protected Sub BtnSubmit_Click(sender As Object, e As EventArgs) Handles BtnSubmit.Click
    Dim myConn As SqlConnection
    Dim cmd As SqlCommand
    Dim sqlstring, RqType, RqLast, RqFirst, RqOrg, RqEmail, RqNeedDate, SubFirst, SubLast, RqDetails, RqGenDate, RqOperator As String
    RqType = cbxRequestType.SelectedValue
    RqLast = txtReqLastName.Text
    RqFirst = txtReqFirstname.Text
    RqOrg = txtOrganization.Text
    RqEmail = txtEmail.Text
    RqNeedDate = txtReqDate.Text
    SubFirst = txtSubFirst.Text
    SubLast = txtSubLast.Text
    RqDetails = txtReqDetails.Text
    RqGenDate = txtGenDate.Text
    RqOperator = txtOperator.Text
    If Agree.Checked = False Then
        MsgBox("You must agree to the terms before proceeding")
    Else
        myConn = New SqlConnection(ConfigurationManager.ConnectionStrings("PRRWeb").ConnectionString)
        myConn.Open()
            sqlstring = "INSERT INTO Requests (LastName, FirstName, Organization, DateRequested, DateNeeded, OperatorID, SubjectLastName, SubjectFirstName, Notes, TypeID, Email) VALUES ('" + RqLast + "','" + RqFirst + "', '" + RqOrg + "','" + RqGenDate + "', '" + RqNeedDate + "','" + RqOperator + "','" + SubLast + "','" + SubFirst + "','" + RqDetails + "','" + RqType + "','" + RqEmail + "')"
            cmd = New SqlCommand(sqlstring, myConn)
            cmd.ExecuteNonQuery()
        myConn.Close()
        MsgBox("Your request has been submitted.", MsgBoxStyle.Information)
        Response.Redirect(Request.RawUrl)
    End If




Aucun commentaire:

Enregistrer un commentaire