Advertisement

01.04.2008 at 10:10AM PST, ID: 23059286
[x]
Attachment Details

Pass TextBox.text as a parameter to a SqlCommand

Asked by megnin in Programming for ASP.NET, MS SQL Server, Microsoft Visual Basic.Net

Tags: ASP.Net 2.0, VB 2005, VS 2005, SQL Server 2000

Instead of the value "8980" in the SELECT statements below I need to pass the value of TextBox "txtSSN4" into the SELECT statement.

A nice easy example would be really nice ;-)  Thanks.  Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
Protected Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTest.Click
        Dim retFirstName As String = ""
        Dim retLastName As String = ""
        Dim retDOB As Date = "01/01/1900"
        Dim retSSN4 As String = Me.txtSSN4.Text
        Dim RSVP As String = "0"
 
        Dim DBConn As New SqlConnection("UID=dmegnin;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SYEP2007;Data Source=BETASERVE;Packet Size=4096;")
        Dim sql1 As String = "SELECT FirstName FROM Applicants WHERE SUBSTRING(SSN, 6, 4)= 8980; "
        Dim sql2 As String = "SELECT LastName FROM Applicants WHERE SUBSTRING(SSN, 6, 4)= 8980; "
        Dim sql3 As String = "SELECT DOB FROM Applicants WHERE SUBSTRING(SSN, 6, 4)= 8980; "
        Dim sql4 As String = "SELECT SUBSTRING(SSN, 6, 4) FROM Applicants WHERE SUBSTRING(SSN, 6, 4)= 8980; "
        Dim Cmd As New SqlCommand
        Dim DBCmd As New SqlCommand(sql1, DBConn)
        Dim DBAdap As New SqlDataAdapter(DBCmd)
        Dim DS As New DataSet()
        DBConn.Open()
 
        'Cmd.Parameters.Add("@SSN4", SqlDbType.VarChar, 4)
        'Cmd.Parameters("@SSN4").Value = txtSSN4.Text
 
        Try
 
            Me.retFirstName.Text = DBCmd.ExecuteScalar().ToString()
            Me.retLastName.Text = New SqlClient.SqlCommand(sql2, DBConn).ExecuteScalar().ToString()
 
        Catch exp As Exception
            Response.Write(exp)
        End Try
        DBCmd.Dispose()
        DBAdap.Dispose()
        DBConn.Close()
        DBConn = Nothing
 
    End Sub
[+][-]01.04.2008 at 10:13AM PST, ID: 20584640

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.04.2008 at 10:14AM PST, ID: 20584651

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.04.2008 at 10:15AM PST, ID: 20584667

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.04.2008 at 10:42AM PST, ID: 20584924

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.04.2008 at 10:53AM PST, ID: 20585015

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.04.2008 at 11:28AM PST, ID: 20585326

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.04.2008 at 11:57AM PST, ID: 20585555

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.04.2008 at 12:31PM PST, ID: 20585816

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.04.2008 at 12:40PM PST, ID: 20585898

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.04.2008 at 01:27PM PST, ID: 20586264

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.04.2008 at 02:00PM PST, ID: 20586468

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, MS SQL Server, Microsoft Visual Basic.Net
Tags: ASP.Net 2.0, VB 2005, VS 2005, SQL Server 2000
Sign Up Now!
Solution Provided By: sammy1971
Participating Experts: 3
Solution Grade: A
 
 
[+][-]01.07.2008 at 07:35AM PST, ID: 20600177

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628