怎样连接系统的前台和后台数据库呀?

如题所述

连接前台和后台数据库是一样的,问题是你想采用哪种技术连接数据库,每种连接都有所差别
1.C#连接连接Access
程序代码:
------------------------------------------------------------------------------- using System.Data;
using System.Data.OleDb;
..

string strConnection="Provider=Microsoft.Jet.OleDb.4.0;";
strConnection+=@"Data Source=C:BegASPNETNorthwind.mdb";
OleDbConnection objConnection=new OleDbConnection(strConnection);
..
objConnection.Open();
objConnection.Close();
2.C#连接SQL Server
程序代码:
--------------------------------------------------------------------------------
using System.Data;
using System.Data.SqlClient;
..
string strConnection="user id=sa;password=;";
strConnection+="initial catalog=Northwind;Server=YourSQLServer;";
strConnection+="Connect Timeout=30";
SqlConnection objConnection=new SqlConnection(strConnection);
..
objConnection.Open();
objConnection.Close();

3.C#连接Oracle
程序代码:
--------------------------------------------------------------------------------

using System.Data.OracleClient;
using System.Data;

//在窗体上添加一个按钮,叫Button1,双击Button1,输入以下代码
private
void Button1_Click(object sender, System.EventArgs e)

{
string ConnectionString="Data Source=sky;user=system;password=manager;";//写连接串
OracleConnection conn=new OracleConnection(ConnectionString);//创建一个新连接
try

{
conn.Open();
OracleCommand cmd=conn.CreateCommand();

cmd.CommandText="select * from MyTable";//在这儿写sql语句
OracleDataReader odr=cmd.ExecuteReader();//创建一个OracleDateReader对象
while(odr.Read())//读取数据,如果odr.Read()返回为false的话,就说明到记录集的尾部了

{
Response.Write(odr.GetOracleString(1).ToString());//输出字段1,这个数是字段索引,具体怎么使用字段名还有待研究
}
odr.Close();
}
catch(Exception ee)

{
Response.Write(ee.Message); //如果有错误,输出错误信息
}
finally

{
conn.Close(); //关闭连接
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2020-02-11
html不能连接数据库。改成asp.jsp.php文件
要动态网页语言。和运行服务器iis或阿帕琪服务器asp,jsp或php或其它。建意你去找本asp书看看.下面两位的对你现在来说有点困难。
第2个回答  推荐于2018-03-22
这是java中连接MySQL的代码

public class PreparedStatementDemo {
static Properties porp;
private static String url;
private static String user;
private static String password;

public static void main(String[] args){
Connection conn = null;
Statement st = null;
ResultSet rs = null;
porp = new Properties();
PreparedStatement stmt = null;
try {
porp.load( new FileInputStream("jdbc.properties"));
url = porp.getProperty("chap20.url");
user = porp.getProperty( "chap20.user");
password = porp.getProperty("chap20.password");

Class.forName(porp.getProperty( "chap20.Driver"));
conn = DriverManager.getConnection(url,user,password);
st = conn.createStatement() ;

stmt = conn.prepareStatement( "insert into student values(?,?,?)");
stmt.setInt(1,130610);
stmt.setString(2,"zhaoli");
stmt.setInt(3,19);

stmt.executeUpdate();
stmt.clearParameters();

rs = st.executeQuery("select * from student");
while(rs.next()){
System.out.print(rs.getInt(1)+"\t");
System.out.print(rs.getString(2)+"\t");
System.out.println(rs.getInt(3));
}

} catch (Exception e) {
e.printStackTrace();
}
finally{
if(stmt!=null){
try {
stmt.close() ;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

}本回答被网友采纳
第3个回答  2013-08-16
用的什么做开发啊 具体点说啊
相似回答