none
Conection whit SQL server2005(ADO.net) RRS feed

  • Question

  •  

    Hellow

    Ferst my Englis is very poor because Yo hablo mucho mejor el Español soy de Ecuador

    saludos amigos........................

    I am  a student and for my proyect, i need do a system for a school whit a database

    my problen is how i can conect and do the dadaset,data adapter,data reader whit the class whit c#.net

    only a small example,

    No sa ben cuanto les agradesco por la atención prestada a la presente ..........

    Tuesday, August 7, 2007 4:38 AM

Answers

  • Jodch, here it is an example:

     The function returns DataSource.

    private static DataTable GetData(string sqlCommand)

    {

    string connectionString = "packet size=4096;data source=<YourSQLServerName>;"

    + "initial catalog=<DataBaseName; persist security info = true;" + "Integrated Security = True";

    SqlConnection con = new SqlConnection(connectionString);

    SqlCommand command = new SqlCommand(sqlCommand, con);

    SqlDataAdapter adapter = new SqlDataAdapter();

    adapter.SelectCommand = command;

    DataTable table = new DataTable();

    table.Locale = System.Globalization.CultureInfo.InvariantCulture;

    adapter.Fill(table);

    return table;

    }

     

    You may use it, for example as a DataSource for DataGridView.

    DataGridView1.DataSource = GetData("Select * FROM dbo.Persons");

     

    Ask if you have any questionsSmile

    Tuesday, August 7, 2007 5:38 AM