日期:2014-05-17 浏览次数:20608 次
<connectionStrings> <!--数据库连接字符串-->
<add name="forconnstr" connectionString="Data Source=AKSLJ\SQLEXPRESS;Initial Catalog=forcastserver;Integrated Security=True;Pooling=False" providerName="System.Data.SqlClient"/>
</connectionStrings>
protected void Button1_Click(object sender, EventArgs e)
{
DateTime MyDate = DateTime.Parse(TextBox1.Text);
DateTime MyDate1 = DateTime.Parse(TextBox2.Text);
//使用ADO连接数据库=AKSLJ\SQLEXPRESS
//string SqlStr="Server=(local);user id=sa;Pwd=; DataBase=forcastserver"; //用这条语句连不上
string SqlStr = "Data Source=SQLEXPRESS;Initial Catalog=forcastserver;Integrated Security=True;Pooling=False";
SqlConnection con=new SqlConnection(SqlStr);
con.Open(); //[color=#FF0000]这里出错!!!![/color]
string sql= "select * from test where 日期>='"+MyDate +"'and 日期<='"+MyDate1 +"'";
SqlDataAdapter dap=new SqlDataAdapter(sql ,con);
DataSet ds = new DataSet();
dap.Fill(ds);
GridView2.DataSource = ds.Tables[0].DefaultView;
con.Close();
}