System.Data.OleDb为System.Data.SqlClient
其他OleDb改为Sql
连接串也改一下
其他OleDb改为Sql
连接串也改一下
解决方案 »
- C# TabControl的TabPages不可用
- 打开对话框
- 怎么样把res和il编译成dll
- C# 桌面截图 Windows Media(在线,马上结帖)
- 求高手解说C#分页的原理和实现方法?
- *********关于DataGRID显示树的问题?****************
- 还要问!关于treeview事件的响应?
- Mapx控件在.net中有些涵数问题,有没有Mapx的.net版(发言有分)
- 求一个类结构的设计问题?
- 有多个表的字段要交叉显示在datagrid中,帮个忙,
- 请问在C#里面怎样和DCOM交互?
- 在ASP.net中的dataGrid有模版列,在windows form中有类似的东西吗?
private void Page_Load(object sender, System.EventArgs e)
{
string myConn="server=localhost;database=northwind;uid=sa;pwd=sa;";
string mySelectQuery ="SELECT * FROM mima where 学号='"+Request.QueryString["xuehao"]+"'";
this.myConnection = new System.Data.SqlClient.SqlConnection(myConn);
this.myCommand = new System.Data.SqlClient.SqlCommand(mySelectQuery,myConnection);
this.myConnection.Open();
System.Data.SqlClient.SqlDataReader( );
this.myReader= myCommand.ExecuteReader();
Always call Read before accessing data.
while (myReader.Read()) {
this.xuehao.Text=myReader["学号"].ToString();
this.xingming.Text=myReader["姓名"].ToString();
this.mima.Text=myReader["密码"].ToString();
this.tswt.Text=myReader["提示问题"].ToString();
this.hdwt.Text=myReader["回答问题"].ToString();
}
// always call Close when done reading.
this.myReader.Close();
// Close the connection when done with it.
this.myConnection.Close();
}
就是把连接字符串稍微改一下
workstation id="";packet size=4096;user id=;data source="";persist security info=True;initial catalog=;password=
F:\WEB\student\cgdl.aspx.cs(42): 无法将类型“System.Data.SqlClient.SqlConnection”隐式转换为“System.Data.OleDb.OleDbConnection”
F:\WEB\student\cgdl.aspx.cs(43): 与System.Data.SqlClient.SqlCommand.SqlCommand(string, System.Data.SqlClient.SqlConnection)”最匹配的重载方法具有一些无效参数
F:\WEB\student\cgdl.aspx.cs(43): 参数“2” : 无法从“System.Data.OleDb.OleDbConnection”转换为“System.Data.SqlClient.SqlConnection”......我是按boarduck(davieou)说的方法改的啊!!!
using System;
using System.Data.SqlClient;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace ltq
{
/// <summary>
/// mydb的摘要说明。
/// </summary>
public class cgdl : System.Web.UI.Page
{
protected System.Data.OleDb.OleDbConnection myConnection;
protected System.Data.OleDb.OleDbCommand myCommand;
protected System.Web.UI.WebControls.Label xuehao;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label xingming;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label mima;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.Label tswt;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.Label hdwt;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Label Label4;
protected System.Data.OleDb.OleDbDataReader myReader;
private void Page_Load(object sender, System.EventArgs e)
{
string myConn= "Server=(local);DataBase=material;UID=sa;PWD=";
string mySelectQuery ="SELECT * FROM mima where 学号='"+Request.QueryString["xuehao"]+"'";
SqlConnection myConnection = new SqlConnection(myConn);
SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
myConnection.Open();
SqlDataReader myReader = new SqlDataReader( );
myReader= myCommand.ExecuteReader();
Always call Read before accessing data.
while (myReader.Read()) {
this.xuehao.Text=myReader["学号"].ToString();
this.xingming.Text=myReader["姓名"].ToString();
this.mima.Text=myReader["密码"].ToString();
this.tswt.Text=myReader["提示问题"].ToString();
this.hdwt.Text=myReader["回答问题"].ToString();
}
// always call Close when done reading.
this.myReader.Close();
// Close the connection when done with it.
this.myConnection.Close();
}
coldljy(凤舞N天)
的说法编译现在没有发现错误了
谢谢大家,结帖。
protected System.Data.SqlClient.SqlCommand myCommand;
protected System.Web.UI.WebControls.Label xuehao;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label xingming;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label mima;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.Label tswt;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.Label hdwt;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Label Label4;
protected System.Data.SqlClient.SqlDataReader myReader;