Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Store and reterive data in database

Last post 05-14-2008 11:10 AM by ronan.govender@gmail.com. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 04-22-2008 6:34 AM

    • arun06_83
    • Not Ranked
    • Joined on 04-21-2008
    • India
    • New Member
    • Points 15

    Store and reterive data in database

     Dear All,

    Now am fresher to enter Dotnet.I want to simple coding for how to store data in database? and How to reterive  stored data in database to output form? For example i want to create employee table.The following fields are contain the table(empid,empname,empaddress,etc).I want to Store data in a database and also i want to reterive stored data to output form

    • Post Points: 10
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 05-14-2008 11:10 AM In reply to

    Re: Store and reterive data in database

    Hi Arun

    you've left out several pieces of information. What dbms are you connecting to (Oracle,SQL Server,Access) so I'm not going to give the line by line breakdown for every one of them. Use the code I give to help you understand how the Active Data Object (ADO.Net) works.

    code is in VB.Net

    'I'm assuming you're using a SQL Server dbms

    'Case 1 --Retrieving a single value

    Using System.Data.SqlClient

    Dim sqlConn As New SqlClient.SqlConnection 'You need a connection

    Dim sqlComm As New SqlClient.SqlCommand 'You 're also going to need a command object

    Dim ValuetobeRetrieved As String

    sqlConn.ConnectionString = "" ' Whatever connection string you're using ie. Data Source=[MachineName];Initial Catalog=[dbName];Integrated Security=[True/False--True=your application has security rights,False=Username and Password has to be supplied for your application to connect]

    sqlComm.CommandText = "SELECT [ValueToBeRetrieved] FROM [db_Table] WHERE [Insert Filter criteria] "sqlComm.Connection = sqlConn ' Set the commands connection

    sqlConn.Open() 'Self explanatory

    ValuetobeRetrieved= sqlComm.ExecuteScalar()

    sqlConn.Close()

    NOTES: always ensure that your data typing in .Net matches the value type in SQL (String = String etc..)

    Also explore and discover the following

    Datareader,DataSets,DataGrid, DataGridView

    Unfortunately I've run out of time so I cannot continue with Case 2 retrieving and displaying multiple values (a full row in a table for example), but with research and a little curiosity you can discover that for yourself. Have fun!!

    • Post Points: 5
Page 1 of 1 (2 items)