网页表单和数据库的连接
我在网页中做个一个表单,包括一个下拉菜单和三个单选,现在需要用access2000建立数据库,该怎么弄,如何连接网页表单和数据库...
我在网页中做个一个表单,包括一个下拉菜单和三个单选,现在需要用access 2000建立数据库,该怎么弄,如何连接网页表单和数据库
展开
2个回答
展开全部
ASP的
<%
if request.form("Submit")="提交" then'判断是否为表单提交事件
s=request.form("select")'取得下拉列表的值(被选的option的value的值)
r=request.form("radiobutton")'取得3个单选按扭中被选中的值(value的值)
set conn=server.CreateObject("adodb.connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("data.mdb")
set rs=server.CreateObject("adodb.recordset")
sql="select * from [表名]"
rs.open sql,conn,1,3
rs.addnew
rs("字段1")=s'把 s 的值写入数据库中的字段1
rs("字段2")=r'把 r 的值写入数据库中的字段2
'……其他字段……
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
end if
%>
<form id="form1" name="form1" method="post" action="">
<p>
下拉列表:
<select name="select">
<option value="1" selected="selected">值为1</option>
<option value="2">值为2</option>
<option value="3">值为3</option>
</select>
</p>
<p>
<input type="radio" name="radiobutton" value="1" />
单选1</p>
<p>
<input type="radio" name="radiobutton" value="2" />
单选2</p>
<p>
<input type="radio" name="radiobutton" value="3" />
单选3</p>
<p>
<input type="submit" name="Submit" value="提交" />
</p>
</form>
<%
if request.form("Submit")="提交" then'判断是否为表单提交事件
s=request.form("select")'取得下拉列表的值(被选的option的value的值)
r=request.form("radiobutton")'取得3个单选按扭中被选中的值(value的值)
set conn=server.CreateObject("adodb.connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("data.mdb")
set rs=server.CreateObject("adodb.recordset")
sql="select * from [表名]"
rs.open sql,conn,1,3
rs.addnew
rs("字段1")=s'把 s 的值写入数据库中的字段1
rs("字段2")=r'把 r 的值写入数据库中的字段2
'……其他字段……
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
end if
%>
<form id="form1" name="form1" method="post" action="">
<p>
下拉列表:
<select name="select">
<option value="1" selected="selected">值为1</option>
<option value="2">值为2</option>
<option value="3">值为3</option>
</select>
</p>
<p>
<input type="radio" name="radiobutton" value="1" />
单选1</p>
<p>
<input type="radio" name="radiobutton" value="2" />
单选2</p>
<p>
<input type="radio" name="radiobutton" value="3" />
单选3</p>
<p>
<input type="submit" name="Submit" value="提交" />
</p>
</form>
展开全部
不知道你拿什么做
这是一个asp.net c#语言的数据库操作的程序
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace Manager.Common
{
/// <summary>
/// dbOperation 用于操作数据库
/// </summary>
public class dbOperation
{
public dbOperation()
{
}
/// <summary>
/// 用于连接数据库
/// </summary>
/// <param name="CurtConn">连接数据库的对象</param>
/// <returns>连接成功与否 0 成功 1 失败</returns>
private int dbConnection(ref OleDbConnection CurtConn)
{
int intRet = 0;
try
{
string strConnString = String.Empty;
strConnString = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=Manager.mdb";
CurtConn.ConnectionString = strConnString;
CurtConn.Open();
intRet = 0;
return intRet;
}
catch ( OleDbException ex )
{
MessageBox.Show( ex.Message.ToString() );
intRet = 1;
return intRet;
}
}
private int dbClose(OleDbConnection CurtConn)
{
int intRet = 0;
try
{
CurtConn.Close();
intRet = 0;
return intRet;
}
catch ( OleDbException ex )
{
MessageBox.Show( ex.Message.ToString() );
intRet = 1;
return intRet;
}
}
/// <summary>
/// SQL文执行函数
/// </summary>
/// <param name="strSql">SQl文内容</param>
/// <param name="ds">数据集</param>
/// <returns>返回0:正常 返回1:异常</returns>
public int dbSqlExec(string strSql, ref DataSet ds)
{
int intRet = 0;
OleDbConnection CurtConn = new OleDbConnection();
OleDbDataAdapter myAdapter = null;
try
{
if (this.dbConnection(ref CurtConn) == 0)
{
myAdapter = new OleDbDataAdapter(strSql, CurtConn);
myAdapter.Fill(ds,"Context");
}
intRet = 0;
return intRet;
}
catch ( OleDbException ex )
{
MessageBox.Show( ex.Message.ToString() );
intRet = 1;
return intRet;
}
}
}
}
这是一个asp.net c#语言的数据库操作的程序
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace Manager.Common
{
/// <summary>
/// dbOperation 用于操作数据库
/// </summary>
public class dbOperation
{
public dbOperation()
{
}
/// <summary>
/// 用于连接数据库
/// </summary>
/// <param name="CurtConn">连接数据库的对象</param>
/// <returns>连接成功与否 0 成功 1 失败</returns>
private int dbConnection(ref OleDbConnection CurtConn)
{
int intRet = 0;
try
{
string strConnString = String.Empty;
strConnString = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=Manager.mdb";
CurtConn.ConnectionString = strConnString;
CurtConn.Open();
intRet = 0;
return intRet;
}
catch ( OleDbException ex )
{
MessageBox.Show( ex.Message.ToString() );
intRet = 1;
return intRet;
}
}
private int dbClose(OleDbConnection CurtConn)
{
int intRet = 0;
try
{
CurtConn.Close();
intRet = 0;
return intRet;
}
catch ( OleDbException ex )
{
MessageBox.Show( ex.Message.ToString() );
intRet = 1;
return intRet;
}
}
/// <summary>
/// SQL文执行函数
/// </summary>
/// <param name="strSql">SQl文内容</param>
/// <param name="ds">数据集</param>
/// <returns>返回0:正常 返回1:异常</returns>
public int dbSqlExec(string strSql, ref DataSet ds)
{
int intRet = 0;
OleDbConnection CurtConn = new OleDbConnection();
OleDbDataAdapter myAdapter = null;
try
{
if (this.dbConnection(ref CurtConn) == 0)
{
myAdapter = new OleDbDataAdapter(strSql, CurtConn);
myAdapter.Fill(ds,"Context");
}
intRet = 0;
return intRet;
}
catch ( OleDbException ex )
{
MessageBox.Show( ex.Message.ToString() );
intRet = 1;
return intRet;
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询