locked
concatenate 2values RRS feed

  • Question

  • User1386200375 posted

    i have got a datafield for phone number in my database

    now i have to concatenate 2numbers and insert a single value in the datafield

    i have 2 textboxes textbox1 and textbox2.

    what statement can we write i mean what query should i use to concatenate these two values and enter a single value in the datafield.m using vb.net

    Friday, April 4, 2008 4:08 AM

Answers

  • User1187105292 posted

     First of all, textbox1 and textbox2 are terrible names.  They have no business meaning.  Their names should match what is in them.

    Examples:

    tbxPhonePart1

    tbxPhonePart2

     

    As far as concatenation goes, in c# it would be tbxPhonePart1.Text + tbxPhonePart2.Text.

    Look up the concatenation operator in vb.  should be easy to find.

     

    You do not want a query, you want an insert or update statement.

    Queries get data in the database, insert and update put it in.  delete takes it out.
     


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 4, 2008 7:19 AM
  • User-1670588033 posted

    Hi, maybe you could do something like this:

    Dim myCommand As SqlCommand

    myCommand = New SqlCommand("select * from users where phone = @phone")

    Dim param As New SqlParameter()

    param.ParameterName = "@phone"

    param.Value = TextBox1.Text + TextBox2.Text

    myCommand.Parameters.Add(param)

    Good Luck
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 4, 2008 2:35 PM

All replies

  • User1187105292 posted

     First of all, textbox1 and textbox2 are terrible names.  They have no business meaning.  Their names should match what is in them.

    Examples:

    tbxPhonePart1

    tbxPhonePart2

     

    As far as concatenation goes, in c# it would be tbxPhonePart1.Text + tbxPhonePart2.Text.

    Look up the concatenation operator in vb.  should be easy to find.

     

    You do not want a query, you want an insert or update statement.

    Queries get data in the database, insert and update put it in.  delete takes it out.
     


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 4, 2008 7:19 AM
  • User-1670588033 posted

    Hi, maybe you could do something like this:

    Dim myCommand As SqlCommand

    myCommand = New SqlCommand("select * from users where phone = @phone")

    Dim param As New SqlParameter()

    param.ParameterName = "@phone"

    param.Value = TextBox1.Text + TextBox2.Text

    myCommand.Parameters.Add(param)

    Good Luck
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 4, 2008 2:35 PM