我不知道你为什么不用oledb 是不是下面的 dim cma as adocommand=new adocommand()有错误啊 应该后面还有个括号吧,而你的代码里是没有的,我好象也碰到过的,你加个括号再试试看。 Sub Button1_Click(sender As Object, e As EventArgs) dim cma as adocommand=new adocommand dim cna as ADOConnection=new ADOConnection dim rad as adodatareader cna.provider="Microsofr.Jet.OLEDB.4.0" cna.datasource=".\db\system.mdb" cna.open() cma.adoconnection=cna cma.commandtype=commandtype.text cma.commandtext="select * from user where rhm='"&textbox1.text&"' and mm='"&textbox2.text&"'" cma.excute(rad) if rad.read() then label1.text=textbox1.text&" YOU ARE WELCOM!" else label1.text="ERROR! THE Password is error!" end if
End Sub
改过之后现在又提示说:Compiler Error Message: BC30526: Property 'Provider' is 'ReadOnly'出错的语句是:cna.provider="Microsofr.Jet.OLEDB.4.0" 各有没有简洁的写法,成功后马上给分!谢谢!
参考这个: Sub Page_Load() If Not Page.IsPostBack Then BindData() End If End SubSub BindData() Dim strConn As String = "Data Source=(Local);Initial Catalog=Books;User Id=sa;Password=123;" Dim Conn As sqlconnection Dim MyCommand As sqlcommand Dim MyReader As sqldatareader Dim strSql As String = "select * from BookList"
Conn = New sqlconnection(strConn) Conn.Open()
MyCommand = New sqlcommand(strSql,Conn) MyReader = MyCommand.ExecuteReader()
MyDataGrid.DataSource = MyReader MyDataGrid.DataBind() End Sub
import Namespace=System.Data.OleDb
dim rad as DataReader
-----------------------------------------------------------
快让开,我在找分……
╭══╮
╭╯宝马║
╰⊙═⊙╯。oо○ 压死了不管
┗█┛
是不是下面的
dim cma as adocommand=new adocommand()有错误啊
应该后面还有个括号吧,而你的代码里是没有的,我好象也碰到过的,你加个括号再试试看。 Sub Button1_Click(sender As Object, e As EventArgs)
dim cma as adocommand=new adocommand
dim cna as ADOConnection=new ADOConnection
dim rad as adodatareader
cna.provider="Microsofr.Jet.OLEDB.4.0"
cna.datasource=".\db\system.mdb"
cna.open()
cma.adoconnection=cna
cma.commandtype=commandtype.text
cma.commandtext="select * from user where rhm='"&textbox1.text&"' and mm='"&textbox2.text&"'"
cma.excute(rad)
if rad.read() then
label1.text=textbox1.text&" YOU ARE WELCOM!"
else
label1.text="ERROR! THE Password is error!"
end if
End Sub
各有没有简洁的写法,成功后马上给分!谢谢!
<script runat="server">
OleDbConnection conn;
OleDbCommand cmd;
void Page_Load(object src,EventArgs e){
conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("pubs.mdb"));
if(!Page.IsPostBack){
cmd=new OleDbCommand("select count(emp_id) from employee",conn);
conn.Open();
pager.RecordCount=(int)cmd.ExecuteScalar();
conn.Close();
BindData();
}
}
</script>
<appSettings>
<add key="conString" value="Server=localhost;UID=sa;PWD=;Database=yourdatabase"/>
</appSettings>
在.cs文件里
using System.Configuration;
然后
String strconn = ConfigurationSettings.AppSettings["conString"];
SqlConnection conn = new SqlConnection(strconn);
强烈建议你买本最新的书看看,不然还是问题多多,不要买Beta版的书呀
Sub Page_Load()
If Not Page.IsPostBack Then
BindData()
End If
End SubSub BindData()
Dim strConn As String = "Data Source=(Local);Initial Catalog=Books;User Id=sa;Password=123;"
Dim Conn As sqlconnection
Dim MyCommand As sqlcommand
Dim MyReader As sqldatareader
Dim strSql As String = "select * from BookList"
Conn = New sqlconnection(strConn)
Conn.Open()
MyCommand = New sqlcommand(strSql,Conn)
MyReader = MyCommand.ExecuteReader()
MyDataGrid.DataSource = MyReader
MyDataGrid.DataBind()
End Sub