You must Sign In to post a response.
  • Category: .NET

    Assign values based on index in a string

    whats wrong in following statement...

    Dim a = String.Format("select {0} from {1} where {0} in {4}" & "," & column & "," & table & "," & condition)
  • #762907

    Hi,

    Regarding your query: Assign values based on index in a string (specified below)

    Dim a = String.Format("select {0} from {1} where {0} in {4}" & "," & column & "," & table & "," & condition)

    There are two issues with your statement
    1. You don't need to concatenate with "&" inside string.format function
    2. when you specify place holders ie numbers specified within flower brackets { }, should match with number of parameters that you are using. You can not put whatever number you like.

    It always starts with 0 and depends on number of parameters you need to increase the number.

    In your case you gave {0} {1} and then {4}, you have to use {2} instead of {4}. Because you have only 3 parameters ie column as {0}, table {1}, condition{2}. You can repeat same number, any number of times.

    We can use String.Format Function to format strings, to create useful string representations

    Example:

    Dim column = "column1"
    Dim table = "table1"
    Dim condition = "condition"

    Dim a = String.Format("select {0} from {1} where {0} in {2}", column, table, column, condition)

    When you print, the above statement will give the following output
    select column1 from table1 where column1 in condition


    I hope it might help you


    Thanks & Regards,
    Mahesh Durgam

  • #762944
    Hai Rashed,
    There are few problems in the code:

    Dim a = String.Format("select {0} from {1} where {0} in {4}" & "," & column & "," & table & "," & condition)

    1. You are passing 3 parameters, but you are assigning {4} which is wrong.
    2. No need of & to pass the value. They should be simple variables.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com


Sign In to post your comments