Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
please, any one tell me best way simply to connect between 1 table in database and display it simply on windows form application through grid view :( SQL DATABASE
Posted
Updated 16-May-12 4:33am
v2
Comments
Killzone DeathMan 16-May-12 10:31am    
your database is 'sql server' or 'oracle' or 'MySQL' or what?
Haitham tarek 16-May-12 10:33am    
sql :) sorry

1 solution

This is what you want: www.macoratti.net/08/11/c_sql_m1.htm[^]
Go down of the web site, there are images that help you...
Tell me if I helped you or not...

First add the libraries:

C#
using System.Data;
using System.Data.SqlClient;


Then:

<pre lang="c#">
namespace teste
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            string connection = "Your Conection String";
            SqlConnection conn = new SqlConnection();
            SqlDataAdapter adapt = new SqlDataAdapter("Query SQL", conn);
            DataSet ds = new System.Data.DataSet();
            adapt.Fill(ds);
            dataGridView1.DataSource = ds;
        }
    }
}


Here you get more: http://csharp.net-informations.com/data-providers/csharp-sql-server-connection.htm[^]
 
Share this answer
 
v6
Comments
Haitham tarek 16-May-12 10:39am    
this is not english :(
also i dont know how to get the connecttion string because i added the database inside
the asp.net and my app dont hv web config file :(
Killzone DeathMan 16-May-12 10:47am    
Look my solution, I update it... Better now?
Haitham tarek 16-May-12 11:01am    
yes thanks alot but please how i can get the connection string i added database INSIDE add items in aps.net and then i cant find the web .config how i can do instead ed
Killzone DeathMan 16-May-12 11:07am    
In Microsoft Visual Studio 2010 there is on top a button 'Data' -> 'Add New Data Source' -> 'Database' -> 'DataSet' -> 'New Connection' -> Choose 'Microsoft SQL Server' and click 'Continue'...
Then add you sql server and click 'Test Connection'...
I have no SQL server installed to test here...but is this what you want?
Haitham tarek 17-May-12 4:01am    
<pre lang="c#">
namespace teste
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// from where i can get that connection string? in that case i added new item
//from the solution and then chooses database and created like that.

string connection = "Your Conection String";
SqlConnection conn = new SqlConnection();
SqlDataAdapter adapt = new SqlDataAdapter("Query SQL", conn);
DataSet ds = new System.Data.DataSet();
adapt.Fill(ds);
dataGridView1.DataSource = ds;
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900