Results 1 to 7 of 7

Thread: db connections

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    2

    db connections

    how to create a db connection with sqlserver with c#.net and what is the code

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: db connections

    Firstly, this is the VB.NET forum, not the C# forum. Secondly, exactly how you connect to the database depends on your circumstances. You can create an SqlConnection in code or in the designer, or you can use the Data Source wizard to have the IDE generate a typed DataSet for you, which encapsualtes all the connections and SQL code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: db connections

    Moved to C# section

  4. #4
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    Re: db connections

    Hi
    First of all, you need to install the MySQL Connector for .NET(found on mysql.com). Then you need to add this as a reference to your project.

    Now, to initiate a connection, you could do this:

    Code:
        MySqlConnection myConnection;   
        MySqlDataAdapter myDataAdapter; 
        DataSet myDataSet;              
    
        String  strSQL;                 // Query string
    
    // initiate connection
     myConnection = new MySqlConnection("server=server-name; user id=use; password=pasword; database=database-schema; pooling=false;");
    
    
    // Now a sample query:
    
    strSQL = "SELECT * FROM Something;";
            
            myDataAdapter = new MySqlDataAdapter(strSQL, myConnection);
            myDataSet = new DataSet();
        
            myDataAdapter.Fill(myDataSet, "Something");

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: db connections

    Quote Originally Posted by carstenht
    Hi
    First of all, you need to install the MySQL Connector for .NET(found on mysql.com). Then you need to add this as a reference to your project.

    Now, to initiate a connection, you could do this:

    Code:
        MySqlConnection myConnection;   
        MySqlDataAdapter myDataAdapter; 
        DataSet myDataSet;              
    
        String  strSQL;                 // Query string
    
    // initiate connection
     myConnection = new MySqlConnection("server=server-name; user id=use; password=pasword; database=database-schema; pooling=false;");
    
    
    // Now a sample query:
    
    strSQL = "SELECT * FROM Something;";
            
            myDataAdapter = new MySqlDataAdapter(strSQL, myConnection);
            myDataSet = new DataSet();
        
            myDataAdapter.Fill(myDataSet, "Something");
    I don't think the MySQL ADO.NET provider is going to be much help in connection to SQL Server.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Addicted Member
    Join Date
    Jan 2007
    Posts
    162

    Re: db connections

    didnt see that, but oh well. With sqlserver its even easier - stumbled upon a code sample from msdn the other day. google it

  7. #7
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Re: db connections

    Quote Originally Posted by varun
    how to create a db connection with sqlserver with c#.net and what is the code
    Why wold anyone even want to help someone with absolutely no manners and who is so demanding?

    Not even a HI or THANKS??

    You might as well have ended it with, "NOW BITCHES!"
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width