Dim strConn, strSQL As String Dim myConn As OleDbConnection Dim myCommand As OleDbCommand strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(".") & "/db1.mdb" strsql="SELECT * FROM book where type=@type" myConn = New OleDbConnection(strConn) myCommand = New OleDbCommand(strSQL, myConn) myCommand.Parameters.Add("@type",type) myConn.Open() DataList1.DataSource = myCommand.ExecuteReader() DataList1.DataBind() myConn.close()读完了,,,
楼上说的对,看看书吧,随便找本。net或C#都有介绍
Imports System.Data Imports System.Data.SqlClientDim conn as new SqlConnection("Server=Loalhost;uid=sa;pwd=;DataBase=da") conn.Open() Dim comm as new SqlCommand("Sql",conn) comm.ExecuteNonQuery()'对数据库操作开始
Imports System.Data Imports System.Data.SqlClientDim conn as new SqlConnection("Server=Loalhost;uid=sa;pwd=;DataBase=da") conn.Open() Dim comm as new SqlCommand("Sql",conn) comm.ExecuteNonQuery()
//连接SQL Server数据库SqlConnection conn=new SqlConnection(@"server=glf;uid=sa;pwd=;database=northwind");
SqlDataAdapter da=new SqlDataAdapter("SELECT * FROM products",conn);//绑定DataGrid控件
da.Fill(ds,"products");
---------------------Sql Server try
{
OleDbConnection myConn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=aa.xls;Extended Properties=Excel 8.0;");
myConn.Open();
OleDbDataAdapter thisAdapter= new OleDbDataAdapter("SELECT * FROM [Sheet1$]",myConn);
OleDbCommandBuilder thisBuilder=new OleDbCommandBuilder(thisAdapter);
DataSet thisDataSet=new DataSet();
thisAdapter.Fill(thisDataSet,"ExcelInfo");
MessageBox.Show(thisDataSet.Tables["ExcelInfo"].Rows[1][1].ToString());
myConn.Close();
}
catch(OleDbException ex)
{
MessageBox.Show(ex.Message);
}
--------------------Excelusing System.Data;
using System.Data.OleDb;
---------------------------
OleDbConnection thisConnection=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\D\DevCs\Works2\Person.mdb;");
thisConnection.Open();
OleDbCommand thisCommand=thisConnection.CreateCommand(); //
thisCommand.CommandText="SELECT * FROM Intro";
OleDbDataReader thisReader=thisCommand.ExecuteReader();
while(thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}",thisReader["ID"],thisReader["TheName"]);
}
thisReader.Close();
thisConnection.Close();---------------------Access
2.安装MySQL的ODBC驱动程序。
2.解决方案管理中添加引用Microsoft.Data.Odbc.dll(1.0.3300)
3.代码中增加引用
using Microsoft.Data.Odbc;
4.编写代码
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=samp_db;" +
"UID=root;" +
"PASSWORD=;" +
"OPTION=3";
//Connect to MySQL using Connector/ODBC
OdbcConnection MyConnection = new OdbcConnection(MyConString);
MyConnection.Open();
Console.WriteLine("\n !!! success, connected successfully !!!\n");
MyConnection.Close();
-----------------------MySQL
{
string connStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db/fnsData.mdb";
string strSql="select * from users where userID = '" + this.txtUserName.Text.Trim () + "' and userPwd = '" + this.txtpassword.Text.Trim () + "'";
OleDbConnection conn=new OleDbConnection(connStr);
OleDbCommand cmd=new OleDbCommand(strSql,conn);
OleDbDataReader sdr;
try
{
conn.Open ();
sdr=cmd.ExecuteReader ();
if(sdr.Read ())
{
Response.Write ("<script language='javascript'> alert('登录成功')</script>");
}
else
{
Response.Write ("<script language='javascript'> alert('请确认输入的账号和密码正确')</script>");
this.txtUserName.Text ="";
this.txtUserPwd.Text ="";
}
sdr.Close ();
}
catch(System.Exception ex)
{
throw new Exception (ex.Message );
}
finally
{
conn.Close ();
} }
Dim myConn As OleDbConnection
Dim myCommand As OleDbCommand
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(".") & "/db1.mdb"
strsql="SELECT * FROM book where type=@type"
myConn = New OleDbConnection(strConn)
myCommand = New OleDbCommand(strSQL, myConn)
myCommand.Parameters.Add("@type",type)
myConn.Open()
DataList1.DataSource = myCommand.ExecuteReader()
DataList1.DataBind()
myConn.close()读完了,,,
Imports System.Data.SqlClientDim conn as new SqlConnection("Server=Loalhost;uid=sa;pwd=;DataBase=da")
conn.Open()
Dim comm as new SqlCommand("Sql",conn)
comm.ExecuteNonQuery()'对数据库操作开始
Imports System.Data.SqlClientDim conn as new SqlConnection("Server=Loalhost;uid=sa;pwd=;DataBase=da")
conn.Open()
Dim comm as new SqlCommand("Sql",conn)
comm.ExecuteNonQuery()
--------------------------
那在C#里就难了?
有什么区别吗?