How to retrive from a databbase using vb.net

i want to make a search box and when the user for something i want it to search it the databse and show the resultat. can someone help me how we do this with the code.

tanks




Answer this question

How to retrive from a databbase using vb.net

  • Warren13

    well you pretty much write your SQL query in there in the SQLCommand, or if you are using a StoredProcedure, just write the name of the stored procedure and changing the "CommandType" to "StoredProcedure" in the SQLCommand.

    so in the example, I was just getting all the records from a table (with a search criteria), and filling the dataAdapter with results



  • Equis

    k, tanks but what do i have to write in this field (theSQLCommand)



  • YCDC.CN

    hey can u give me the command code connection extra and if it's possible also can u make some screen shout
    tanks


  • ronks

    basically you will take the input from the textbox and make a query on it:

    SELECT * FROM someTable WHERE SomeColumn LIKE textboxInput

    this query will be placed in the SqlCommand object.

    you will also use a connectionstring to connect to SQL using the SqlConnection Class.

    You open the connection using the SqlConnection close, and either:

    1) read the values returned using an SqlDataReader

    2) fill a dataset with data/results returned back from SQL using the SqlDataAdapter class and "filling" a dataset

    then you close the connection and either:

    1) bind the results to a datagridview

    2) use your own way to go through each row of data in the dataset or something like this



  • byronfromwesleyan

    SQL query can u give me an example of it

  • Huseyin Akturk

    I have given an example in my code ;-) To me it seems you do not know SQL Server, so I would suggest you learn about it :-)

    It is mandatory these days to know SQL Server.

    a SQL Server query is just a query which returns results (for example) with a certain criteria, as I had posted.



  • JesseD70

    Example:



    Dim theSQLCommand as new SqlCommand("SELECT * FROM someTable WHERE SomeColumn LIKE '%" + yourTextBoxValue + "%'")
    theSQLCommand.Connection = new SqlConnection(yourConnectionString)
    Dim theDataSet as new DataSet()
    Dim theSQLDataAdapter as new SqlDataAdapter(theSQLCommand)

    try
    theSQLCommand.Connection.Open()
    theSQLDataAdapter.Fill(theDataSet)
    theSQLCommand.Connection.Close()

    Me.theDataGridView.DataSource = theDataSet.Tables(0).DefaultView

    catch ex as SqlException
    'handle exception
    end try

    this is just an example which will do the following:

  • create an SQL Command to execute, giving it a typical T-SQL type command

  • create a dataadapter

  • create a dataset

  • open the connection

  • fill the results executed into the DataSet

  • close the connection

  • Bind the results to the datagridview



  • bkejser

    Check out the SQL Server start kits. The kits are fully functional applications once built and are targetted to help people learn via example.

     Here is the link to the Starter Kits. Choose the one which best fits your needs. Good luck.


  • Sneak

    The examples are of both web sites and applications and yes they use SQL, so you can breeze over those parts.. There are examples of programs that surely mimic what you need to do. Otherwise use MSDN and look at their examples as found in the controls on how to populate controls...etc.


  • Steve Whitley

    i know sql languge i want to make the search box in vb.net programe the programe i made but not in the sql server..

  • How to retrive from a databbase using vb.net