贴出源码:
private void btnNext_Click(object sender, System.EventArgs e)
{
string strConn;
string strSQL;
OleDbConnection cn;
OleDbCommand cmd;
OleDbDataAdapter dr;
if(Page.IsValid)
{
strConn="Provider=msdaora;Data Source=CQMIS;User Id=robinbid;Password=robinsoft;";
cn=new OleDbConnection(strConn);
strSQL="select YHBM from ROBINBID.JCYH where YHBM="+txtAccount.Text.ToString()+"";
//strSQL="select u_id from userinfo where u_account=juw";
cn.Open();
cmd=new OleDbCommand(strSQL,cn);
dr=cmd.ExecuteReader();
if(dr.Read())
{
lblStep2.Text="您输入的用户名已经存在,请您选择一个其他的名字!";
cn.Close();
//txtAccount.Text="";
}
else
{
cn.Close();
lblPwd.Text=txtUpwd.Text.ToString();
step1.Visible=false;
step2.Visible=false;
step3.Visible=true;
step4.Visible=false;
}
}
}
出错提示如下:
C:\Inetpub\wwwroot\WebApplication32\WebForm1.aspx.cs(183): 无法将类型“System.Data.OleDb.OleDbDataReader”隐式转换为“System.Data.OleDb.OleDbDataAdapter”
我经常遇到如此提示,十分搞不懂。哎!!!!!
因为你定义了dr如下:
OleDbDataAdapter dr
而在程序中又将OleDbDataReader赋值给dr:
dr=cmd.ExecuteReader();
当然不行了,应该保证等号左右的对象类型一致。
同意楼上