none
ใช้ connection จากไฟล์ app.config (General question) RRS feed

  • คำถาม

  • ผมอยากใช้ database connection ในการกำหนด app.config ครับ

    ผมเขียนโค้ดแบบนี้ครับ ช่วยแนะนำด้วยครับ

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
     <configSections>
     </configSections>
     <connectionStrings>
      <add name="Planning.Properties.Settings.Employee" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\C#\employee.mdb"
       providerName="System.Data.OleDb" />
      <add name="WindowsFormsApplication1.Properties.Settings.Employee"
       connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\C#\employee.mdb"
       providerName="System.Data.OleDb" />
     </connectionStrings>
    </configuration>

    But while I am updatiing, on that command button I am saying as follows

     private void button2_Click(object sender, EventArgs e)
      {
       try
       {
    string connString = "Provider=Microsoft.jet.oledb.4.0;Data source=F:\\C#\\employee.mdb";
        OleDbConnection conn = new OleDbConnection(connString);
        conn.Open();
        string strInsert = "INSERT INTO WorkPlanning ([code], [WhatWork]) values ('" +textBox3.Text.ToString() +"' , '" + textBox1.Text.ToString() +"')";
        OleDbCommand cmdIns = new OleDbCommand(strInsert, conn);
        cmdIns.ExecuteNonQuery();
        conn.Close();
        
       }
       catch (Exception ex)
       {
        MessageBox.Show(ex.Message.ToString(), "Job Planning... ", MessageBoxButtons.OK, MessageBoxIcon.Error);
       }
    
      }

    Supa Sethasiripong [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    21 กรกฎาคม 2554 7:24
    ผู้ดูแล

คำตอบ