-1
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection con=new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
cmd.CommandText="select id from regtb where id="+Session["id"];
da.SelectCommand = cmd;
da.Fill(dt);
if(dt.Rows.Count>0)
{
Response.Redirect("userlogin.aspx");
}
}
此代码有什么问题? 任何人都可以帮我在这 我得到这个错误,我不知道如何解决这个问题。填充:SelectCommand.Connection属性尚未初始化C#
不要使用MDF数据库文件。使用服务器中数据库的名称。你可以让证书问题直接访问mdf文件。我会通过使用SQL Server Management Studio(SSMS)来确保您拥有适当的凭据,并尝试从SSMS进行查询以确保连接正确。然后使用SSMS登录窗口中的服务器名称。 – jdweng