【发布时间】:2012-04-07 13:53:27
【问题描述】:
我正在尝试使用两个表连接到数据库。但是,在我尝试登录后,出现错误。错误说零点没有行。我想这是因为我的关系:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
namespace Project3
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void login_Click(object sender, EventArgs e)
{
OleDbConnection connect = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\parodeghero\\Documents\\Visual Studio 2010\\Projects\\Project3\\Project3\\App_Data\\QA.mdb;Persist Security Info=True");
//set up connection string
OleDbCommand command = new OleDbCommand("select * from Employee where Login=@login", connect);
OleDbParameter param0 = new OleDbParameter("@login", OleDbType.VarChar);
param0.Value = employeeID.Text;
command.Parameters.Add(param0);
//middle tier to run connect
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataSet dset = new DataSet();
da.Fill(dset);
//problem line
if (dset.Tables[0].Rows[0]["Password"].ToString().Equals(password.Text))
{
【问题讨论】:
-
在初学者的连接上调用
Open()怎么样? -
谢谢!我发现我的 OleDbCommand 也需要一个 try and catch 语句!
-
我回滚到原来的标题。如果您对自己的问题有自己的答案,请将其作为答案发布并接受。请不要使用“已解决”编辑标题或使用答案编辑问题。
-
我又回滚了。请阅读之前的评论。
标签: c# asp.net visual-studio visual-studio-2010 visual-studio-2008