Problem Regarding Connection With DataBase
I want to connect my c# application with MS SQL SERVER 2005. I found two ways to do it.
first one is we can easily click on "Add New Data Source" under the "Data" menu in Visual Studio 2005 and connect database.
second one is remote connection. We have to write some code to connect database.
My problem is after creating remote connection with MS SQL SERVER how i display the content of a table in my
windows application and how i manipulate these data ?
Thank You..............
[855 byte] By [
Nuwan] at [2008-1-8]
What code do you have currently?
Behind the scenes, the wizard creates the Connection String just as you would do it programmatically.
You would of course need to also create a SqlCommand, the SQL expression to use to select data from a specific table, then say either fill a DataSet/DataTable then bind it to say a DataGridView or use a SqlDataReader to read data row by row then do whatever you like with it. It really depends on your choice and what you are after.
An example of filling a DataSet:
Code Snippet
using (SqlCommand command = new SqlCommand("SELECT * FROM [Table]", new SqlConnection("connectionString")))
{
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
command.Connection.Open();
adapter.Fill(ds);
command.Connection.Close();
this.dataGridView.DataSource = ds.Tables[0].DefaultView;
}
Does this help in any way?