Database Connection using VS.NET and VB.NET?????

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lolli man

    Database Connection using VS.NET and VB.NET?????

    HI,

    I am trying to connect to a database using Visual Studio .NET. I have
    created the SQlconnection string and when I am trying to create the
    DataAdapter using SQLDATAADAPTER tool it aks me to specify the query
    now my question is If I want to specify a condition in that like "
    suppose I want to select details from a table where the id of the
    table is given in a textbox". The query wud be like 'select * from
    table where tblID = txtId.Text' It doesn't work if I specify like
    this.....Can anyone tell me how to specify this.....ur help will be
    appreciated.
    Can I do this using the Design view or do I need to do this using code
    view.
  • Rowland Banks

    #2
    Re: Database Connection using VS.NET and VB.NET?????


    "Lolli man" <cooltobeindian @yahoo.com> wrote in message
    news:51edc4b1.0 406290933.67af2 c80@posting.goo gle.com...[color=blue]
    > HI,
    >[/color]
    <snip bit's i don't know about ;-) >
    [color=blue]
    > The query wud be like 'select * from
    > table where tblID = txtId.Text' It doesn't work if I specify like
    > this.....[/color]

    The query code should look something like this.

    dim s as String
    s = "SELECT * FROM table WHERE tblID ='" + txtID.Text + "'"
    'Note the apostrophes around the txtID.text value.

    If txtID.text = A12 (for example), the SQL statement that will be executed
    will be
    SELECT * FROM table WHERE tblID= 'A12'

    If tblID is a number, leave out the apostrophes.

    Finally, you may want to look into using the ADO data control.(ADO = ActiveX
    Data Objects). This is a relatively easy to use control, in which most/all
    of the relevant options can be set at design time (although they can be set
    at run-time too obviously).

    I have assumed you are using Visual Basic, as you have posted to a VB
    newsgroup. VS.NET comprises a number of programming languages, so it's
    generally better to post to the specific .NET newsgroup (e.g.
    microsoft.publi c.vs.net.<my language> )
    [color=blue]
    > Can I do this using the Design view or do I need to do this using code
    > view.[/color]


    Comment

    Working...