Hi,
I have a table called Employee with attributes(ename,age,address,salary)
I use SQL server 2005 for database design.
I can put values into this table now.How can I retrieve data from the table.
I want to appear those data in same fields in the form.
Ex:-the form contains two butns."Add" and "Load".
I need codings for "Load" butn.
Thank you,
CharithMax
Charith LiyanagamagePosted Jul 17, 2008, 1:26 PM
Thankx a lot.........
charithmax
Niradhip ChakrabortyPosted Jul 17, 2008, 12:32 PM
//The example creates a SqlConnection to the Northwind database. The SqlCommand selecting items from the employee table is then executed using the SqlCommand ExecuteReader method. The results of this command are passed to the SqlDataReader.
//Code:
SqlDataReader myDataReader = null;
SqlConnection mySqlConnection = new SqlConnection("server=(local)\SQLExpress;Integrated Security=SSPI;database=northwind");
SqlCommand mySqlCommand = new SqlCommand("SELECT EmployeeID, LastName, FirstName, Title, ReportsTo FROM Employees", mySqlConnection);
...
mySqlConnection.Open();
myDataReader = mySqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
//The example reads through the data using the SqlDataReader Read method and writing the data elements out to the console.
//code
while (myDataReader.Read())
{
Console.Write(myDataReader.GetInt32(0) + "\t");
Console.Write(myDataReader.GetString(2) + " " + myDataReader.GetString(1) + "\t");
Console.Write(myDataReader.GetString(3) + "\t");
if (myDataReader.IsDBNull(4))
Console.Write("N/A\n");
else
Console.Write(myDataReader.GetInt32(4) + "\n");
}
//Finally, the example closes the SqlDataReader, then the SqlConnection.
//code
// Always call Close when done reading.
myDataReader.Close();
// Close the connection when done with it.
mySqlConnection.Close();
SenPosted Jul 17, 2008, 12:36 AM
http://www.java2s.com/Code/CSharp/Database-ADO.net/NavigatethebindeddatausingBindingManagerBase.htm