我用想OleDbCommand连接access,在一个using System;using System.Data;using system.Data.OleDb;的类中,定义了下面两个函数,可是总是出现“异常详细信息:System.Data.OleDb.OleDbException: FROM 子句语法错误。”是sql语句错了么?还有在这个类里不能调用Server.MapPath是怎么一回事啊?public static OleDbConnection createCon()
{
return new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data source=C:\Inetpub\wwwroot\person\mdb.mdb");
}
//判断用户名是否合法
public static bool judge(string UserName)
{
OleDbConnection dbconn=conn.createCon();
dbconn.Open();
OleDbCommand cmd=new OleDbCommand("select * from user where username like '"+UserName+"'",dbconn);
int count=Convert.ToInt32(cmd.ExecuteNonQuery());
if(count>0)
{
return true;
}
else
{
return false;
}
}
{
return new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data source=C:\Inetpub\wwwroot\person\mdb.mdb");
}
//判断用户名是否合法
public static bool judge(string UserName)
{
OleDbConnection dbconn=conn.createCon();
dbconn.Open();
OleDbCommand cmd=new OleDbCommand("select * from user where username like '"+UserName+"'",dbconn);
int count=Convert.ToInt32(cmd.ExecuteNonQuery());
if(count>0)
{
return true;
}
else
{
return false;
}
}
解决方案 »
- c#入门经典里的一个例子
- 在C#中有没有像系统日期的时间这样的控件,就是选择时、分、秒可以增减
- C#调用C++DLL问题。急。。。在线等待。。。
- 谁有海康威视封装好的cs
- 有没有谁有网址 是详细介绍 水晶报表的?
- 通过委托在窗体间传递消息必须通过父窗体吗?
- 一个时间间隔的问题
- datagrid加一个文本框页眉
- 当我按下"alt+空格"时,explore.exe窗口要隐藏,再按一下,再显示出来
- .net编辑器在我创建一个web form时说:automation 服务器不能创建对象。请问高手们如何解决
- .net2003与.net2005
- 服务器用c#,客户端用c++(非托管)进行网络通信(socket),可以吗?
静态方法createCon是conn的?
OleDbCommand cmd=new OleDbCommand("select * from user where username like '"+UserName+"'",dbconn);
改为
OleDbCommand cmd=new OleDbCommand("select * from [user] where [username] like '"+UserName+"'",dbconn);
OleDbConnection dbconn=conn.createCon();
dbconn.Open();
OleDbDataAdapter thisAdapter= new OleDbDataAdapter("select * from [user]",dbconn);
DataSet thisDataSet=new DataSet();
thisAdapter.Fill(thisDataSet,"usertable");
DataRow thisRow=thisDataSet.Tables["usertable"].NewRow();
thisRow["username"]=this.username.ToString().Trim();
thisRow["sex"]=this.sex.ToString().Trim();
thisRow["pwd"]=this.pwd.ToString().Trim();
thisRow["question"]=this.question.ToString().Trim();
thisRow["answer"]=this.answer.ToString().Trim();
thisDataSet.Tables["usertable"].Rows.Add(thisRow);
thisAdapter.Update(thisDataSet,"usertable");
dbconn.Close();
OleDbConnection dbconn=conn.createCon();改为OleDbConnection dbconn = createCon();
http://blog.csdn.net/knight94/archive/2006/03/17/627556.aspx上面的例子虽说环境是在SQL Server,但是方法一样适用于Access数据库
OleDbConnection dbconn=conn.createCon();
OleDbDataAdapter thisAdapter= new OleDbDataAdapter();
thisAdapter.SelectCommand=new OleDbCommand("select * from [user]",dbconn);
OleDbCommandBuilder thisBuilder = new OleDbCommandBuilder(thisAdapter);
dbconn.Open();
DataSet thisDataSet=new DataSet();
thisAdapter.Fill(thisDataSet,"usertable");
DataRow thisRow=thisDataSet.Tables["usertable"].NewRow();
thisRow["username"]=this.username.ToString().Trim();
thisRow["sex"]=this.sex.ToString().Trim();
thisRow["pwd"]=this.pwd.ToString().Trim();
thisRow["question"]=this.question.ToString().Trim();
thisRow["answer"]=this.answer.ToString().Trim();
thisDataSet.Tables["usertable"].Rows.Add(thisRow);
thisAdapter.Update(thisDataSet,"usertable");
dbconn.Close();