using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.Odbc;public partial class dlZC_denglu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {   //产生验证码
            int i_rand;
            Random r = new Random();
            i_rand = r.Next(1000, 9999);
            Label1.Text = i_rand.ToString();
        }
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
         if (IsValid)
        {
            string username,password,val;
             val = TextBox3.Text.Trim();
            if (val != Label1.Text)
            {
                Response.Write("<script>alert('验证码错误,请重新输入!');</script>");
            }
            else
            {
                username = TextBox1.Text.Trim();
                password = TextBox2.Text.Trim();
                OdbcConnection conn = null;
                OdbcCommand com = null;
                OdbcDataReader dr = null;
                conn = new OdbcConnection("PROVIDER=Microsft.Jet.OLEDB.4.0;DATA Source="+Server.MapPath("../App_Data/新建 Microsoft Office Access 应用程序.mdb"));
               
                conn.Open();
                com = new OdbcCommand("select * from [zhuc] where zhuc_username='" + username + "' and zhuc_password='" + password + "'", conn);
                dr = com.ExecuteReader();
                if (dr.Read())
                {
                    Response.Write("<script>alert('注册成功');window.location.href='../xinqing.aspx';</script>");
                }
                else
                {
                    Response.Write("<script>alert('失败!');</script>");
                }
            }
        }
    }
    }

解决方案 »

  1.   

    conn = new OdbcConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|xx.mdb;Persist Security Info=True");新建 Microsoft Office Access 应用程序.mdb改成xx.mdb
      

  2.   

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=*.mdb;User       ID=Admin;Password=; 
    <add name="accessConnStr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source= |DataDirectory|a.mdb" providerName="System.Data.OleDb"/>  <appSettings>  
    <add key="ConnString" value="provider=microsoft.jet.oledb.4.0;data source="/>  
    <add key="dbPath" value="~/App_Data/a.mdb"/>  
    </appSettings>
      

  3.   

    还是不行!!出现
    ERROR [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序源错误: 
    行 43:                 conn = new OdbcConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|yonghuzhuc.mdb;Persist Security Info=True");
    行 44:                
    行 45:                 conn.Open();
    行 46:                 com = new OdbcCommand("select * from [zhuc] where zhuc_username='" + username + "' and zhuc_password='" + password + "'", conn);
    行 47:                 dr = com.ExecuteReader();
     源文件: f:\biyeshijie\feel\dlZC\denglu.aspx.cs    行: 45 这个!!请再次指教!!
      

  4.   

     string username, password, role, strSql;
            username = TextBox1.Text.Trim();
            password = TextBox2.Text.Trim();
            OleDbDataReader dr;
            OleDbConnection con = null;
            OleDbCommand cmd = null;
                    con = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + Server.MapPath("~/App_Data/yonghuzhuc.mdb"));
            strSql = "select username,role from [zhuc] where username='" + username + "' and password='" + password + "'";
            cmd = new OleDbCommand(strSql, con);
            try
            {
                con.Open();
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    username = dr["username"].ToString();
                    role = dr["role"].ToString();
                    FormsAuthentication.RedirectFromLoginPage(username, false);
                    if (role == "1")//System             
                    {                    Response.Redirect("dlzc/liuy.aspx");
                    }
                    else
                        Response.Redirect("xinqing.aspx");
                }        }
            catch (Exception exc)
            {
                string msg;
                msg = exc.Message + "添加出错,请跟管理员联系!";
                Response.Write(msg);        }
            finally
            {
            }
        }
    请问这里那里有错??不能够正常跳转到其他页面!!
      

  5.   

    String ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|yonghuzhuc.mdb;";完全照着这些写。包括大小写。
    如果还不行,检查你的yonghuzhuc是否拼写错误。如果再不行,下载安装这个
    http://www.microsoft.com/downloads/details.aspx?FamilyID=6c050fe3-c795-4b7d-b037-185d0506396c&DisplayLang=zh-cnhttp://www.microsoft.com/downloads/details.aspx?familyid=78CAC895-EFC2-4F8E-A9E0-3A1AFBD5922E&displaylang=zh-cn另外,你的系统必须是32位的,不能是64位的,64位必须以32位运行
      

  6.   

    String ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|yonghuzhuc.mdb;";OleDbConnection cn = new OleDbConnection(ConnectionString );