还有就是怎么能在web.config下面配置一下数据库的连接其它地方就不用再象我这样打开了就象.asp下面做一个conn文件其他地方来包含就好了

解决方案 »

  1.   

    public void btOK_Click(Object Src, EventArgs E)
    {
    SqlConnection myConnection;
    myConnection = new SqlConnection("server=localhost;uid=sa;pwd=98765321;database=BGGMCarDriverinfo");
    String strSQL = "select us_id,us_pass,us_name from cdm_user where us_id='"+us_id.Text+"' and us_pass='"+us_pass.Text+"'";

        SqlCommand myCommand = new SqlCommand(strSQL, myConnection);
    myConnection.Open();
    SqlDataReader dr;
    dr=myCommand.ExecuteReader();
    if(dr.Read())
    {
         Session["us_id"] = dr.GetValue(0);
            Session["us_pass"] = dr.GetValue(1); 
    Session["us_name"]=dr.GetValue(2);
           Response.Redirect("MainFunction.aspx");   
    }
        else
    {
          Session["us_id"] = "";
          Session["us_pass"] = "";
          Session["us_name"]="";
          lblMsg.Text="您输入的用户名或密码有误,请重新输入!!!";
          us_id.Text = "";
          us_pass.Text = ""; 
        } 
    myConnection.Close();
    }
      

  2.   

    TO: tafse(哲哲) 建议你下面这一句用参数比较好,
    String strSQL = "select us_id,us_pass,us_name from cdm_user where us_id='"+us_id.Text+"' and us_pass='"+us_pass.Text+"'";
      

  3.   

    在webconfig里加
    <appSettings>
    <add key="conn" value="server=localhost;uid=sa;pwd=98765321;database=BGGMCarDriverinfo";
    ">
    </add>
    </appSettings>程序里:
    OleDbConnectiong conn = new oledbconnection(ConfigerationSettings.AppSettings["conn"]);
      

  4.   

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Response.Redirect("zh.aspx")
    End Sub为什么我这样它不进行转向
      

  5.   

    给你看一下我的web.config
    还有连接方法,C#的,你自己改了
    web.config
    ——————————————————————————————————————
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <appSettings>
    <add key="SQLUser" value="sa"/>
    <add key="SQLPassword" value="111111"/>
    <add key="ServerName" value="sundun-5"/>
    <add key="OLAPServer" value="sundun-5"/>
    <add key="DatabaseName" value="CIS"/>
    <add key="ReportDir" value="f:/vickyyu/hsmp/hsmp/AnalyseREP/Report/"/>
    <add key="PushReportDir" value="f:/vickyyu/hsmp/hsmp/AnalyseREP/Report/push/"/>
    <add key="Root" value="http://localhost/HSMP/"/>
      </appSettings>
      
      <system.web>
        <compilation defaultLanguage="c#" debug="true">
         <assemblies><add assembly="CrystalDecisions.CrystalReports.Engine, Version=9.1.5000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/><add assembly="CrystalDecisions.ReportSource, Version=9.1.5000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/><add assembly="CrystalDecisions.Shared, Version=9.1.5000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/><add assembly="CrystalDecisions.Web, Version=9.1.5000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/></assemblies></compilation>
        <sessionState mode="InProc" cookieless="false" timeout="30"/>
    <globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
      </system.web>
    </configuration>————————————————————————————————————————string strSQLUser = ConfigurationSettings.AppSettings["SQLUser"];
    string strSQLPassword = ConfigurationSettings.AppSettings["SQLPassword"];
    string strServerName = ConfigurationSettings.AppSettings["ServerName"];
    string strDatabaseName = ConfigurationSettings.AppSettings["DatabaseName"]; string strCon = "server=" + strServerName + ";" +
    "Trusted_Connection=false;" + 
    "user id=" + strSQLUser + ";" + 
    "password=" + strSQLPassword + ";" +
    "database=" + strDatabaseName;


    SqlConnection objCon = new SqlConnection(strCon);
    objCon.Open();
    DataTable tblTemp = new DataTable();
    SqlDataAdapter objAdap = new SqlDataAdapter();

    SqlCommand objCmd = new SqlCommand("select * from lianjueding where iidd=1",objCon);

    objAdap.SelectCommand = objCmd;
    objAdap.Fill(tblTemp);至此,tblTemp就有资料了
    你可以用tblTemp.Rows[0]["yourFieldName"].ToString();…………………………
    …………………………