answersLogoWhite

0


Best Answer

at the top

using System.Data.SqlClient;

in the main body (perhaps a click event)

//creates a connection object with a given connection string

SqlDataConnection conn = New SqlDataConnection("connection String");

//creates a command object with the sql and the connection it is to use

SqlCommand cmd = new SqlCommand("SQL String",conn);

//create a data reader to store the data retrieved from the database

SqlDataReader rdr;

//open the connection

conn.Open();

//executes the sql and stores the result in the rdr (Use if there is more than one //cell retrieved from database e.g all records where a value is greater than 0

rdr = cmd.ExecuteReader();

//if there is only one cell retrieved such as only the orderid for a specific order then //use:

variable = cmd.ExecuteScalar();

//then do something with the data WARNING: the connection MUST be open to use the data reader but not with the scalar method

//close the connection

conn.Close();

Hope this helps!

steve

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the code to retrieve data from sql in Net?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you store and retrieve images from ms access or MySQL database using JSP source code required?

Retrieve sql data you may with the help of programming way. You need to software working with sql databases of any version SQL Server. I would recommend you to try tool below.


What is a query language that allows users to manage update and retrieve data?

SQL


What is the SQL data base material used for?

The SQL data base is programming language used to manipulate and retrieve data. Included in the language are elements such as data insert, query, update and delete.


What is the name of a statement written to retrieve specific data from a table?

The name of a statement written to retrieve specific data from a table is a SQL SELECT statement.


Which one of the following is the most efficient way to retrieve data from an MS SQL database?

SqlDataReader


How do you retrieve data from table in sql by selecting month?

select * from "table-name" where month="required month";


What is the command to retrieve deleted data from any table in SQL?

rollback command can retrieve deleted data from a table, provided commit has not been performed after deleting the data. both rollback and commit are transaction control statements.


Sql command to retrive all data froma table?

The SQL command that can be used to retrieve all data from a table is the SELECT Ex: Let us say we have a table called employee_master which contains 3 columns emp_name, emp_number, date_of_joining you can retrieve all the data by using the below command SELECT * FROM employee_master or SELECT emp_name, emp_number, date_of_joining FROM employee_master


How do you retrieve data from an SQL database based on the values selected from combo box using jsp?

Try to repair sql database owing to utility below. Software is able to restore sql databases any version of MS SQL Server.


What is the function of Microsoft SQL?

SQL is a relational database management system. The very first function of this software is to keep the data safe and retrieve it When it is asked by other software applications.


What is the SQL Server Express used for?

The SQL Server Express is used to store and retrieve data when requested by other software operations that are running within the same computer or network.


What database objects allows you to search for and retrieve data?

SQL queries allow you to search for and retrieve data from a database. By writing SELECT statements with specific criteria, you can search for information in tables and retrieve the results based on your query.