Unanswered windows application questions

  • Saturday, January 07, 2012 3:12 PM
     
     

    i am using app.config for retriveing the connetion in windows form but when i am using like this

    string str = Properties.Settings.Default.mydatabaseConnectionString;
            SqlConnection con = new SqlConnection(Properties.Settings.Default.mydatabaseConnectionString);

    only i can retrive the table record in datagridview but when i am inserting the values from textboxes than record is not added

    permanent to the table ..reply me............with correct code soon..

     

    • Moved by Kim Shearer Tuesday, January 17, 2012 12:51 AM Off topic (From:Developing Windows Desktop Applications with Power Management)
    • Moved by Bob BeaucheminMVP Monday, January 14, 2013 11:50 PM Moved to the appropriate forum for this question
    •  

All Replies

  • Monday, January 14, 2013 3:48 PM
     
      Has Code

    This is an example of a connection string in app.config or web.config:

    <?xml version='1.0' encoding='utf-8'?>
      <configuration>
        <connectionStrings>
          <clear />
          <add name="Name" 
           providerName="System.Data.ProviderName" 
           connectionString="Valid Connection String;" />
        </connectionStrings>
      </configuration>

    To us it:

    // Retrieves a connection string by name.
    // Returns null if the name is not found.
    static string GetConnectionStringByName(string name)
    {
    // Assume failure.
    string returnValue = null;
    
    // Look for the name in the connectionStrings section.
    ConnectionStringSettings settings =
    ConfigurationManager.ConnectionStrings[name];
    
    // If found, return the connection string.
    if (settings != null)
    returnValue = settings.ConnectionString;
    
    return returnValue;
    }
    
    //Call it
    GetConnectionStringByName("Name");

    How you handle the data insertion?

  • Tuesday, January 15, 2013 12:25 AM
     
     

    Hello,

    There are a good deal of ways to access your data to do read/edit/insert operations. What is right for you can depend on your experience coding in Visual Studio. If you are just starting out working with data in Visual Studio I highly suggest taking time to evaluate what is available with a good start at MSDN Data Walkthrough page. Look at the Entity Framework, data context class and managed data providers such as SqlClient.

    Look at all of them is not a bad idea to see which feels good to you. While doing so know what your business requirements (or simply what you want out of working with your data) are. Many of the methods to work with data are strongly typed, the IDE generates classes for you which at first seems like a great idea which it is yet many who fail to study capabilities will eventually get stuck where if they took time to study they would not get stuck. A good example is after code is generated one might not see how to get a particular task done but if you know that code can be written outside the generated code in one of the dataset designers via a partial class then life is easy again.

    Other resources

    SQL Server database projects and working with database projects.


    KSG