我编写了这段代码,并在运行我的页面时遇到“找不到可安装的ISAM”错误

时间:2013-05-16 13:11:20

标签: c#

public partial class CountryMaster : System.Web.UI.Page
{
    OleDbConnection conn = new OleDbConnection(@"Provider=MicroSoft.ACE.OLEDB.12.0;Data Souce=G:\WebDesign\WebGridView\WebGridView\Database\PracticeDataBase.accdb");

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    int MaxVal()
    {
        int max = 0;
        OleDbCommand comm = new OleDbCommand("Select max(CountryId) from CountryMaster", conn);
        if (conn.State == ConnectionState.Closed)
            conn.Open();
        OleDbDataReader rd = comm.ExecuteReader();
        if (rd.HasRows)
            while (rd.Read())
                int.TryParse(rd[0].ToString(), out max);
        max++;
        comm.Dispose();
        conn.Close();
        return max;
    }


    protected void btnsave_Click(object sender, EventArgs e)
    {
        OleDbCommand comm = new OleDbCommand("Insert into CountryMaster(CountryId,CountryName) Values(" + MaxVal() + ",'" + txtname.Text + "')", conn);
        if (conn.State == ConnectionState.Closed)
            conn.Open();
        comm.ExecuteNonQuery();
        comm.Dispose();
        conn.Dispose();
    }
}

0 个答案:

没有答案