Community discussion forum

Store and reterive data in database

Tags: .net, c++.net, db Turkey
  • 7 months ago

     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

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 6 months ago

    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 a reply

Enter your message below

Sign in or Join us (it's free).