using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class Default4 : System.Web.UI.Page
{
string connstring = ConfigurationSettings.AppSettings["AccessConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string strconn = connstring + Server.MapPath("csc.mdb");
//连接本地计算机的HMS数据库
//SqlConnection cn0 = new SqlConnection(strconn);
OleDbConnection cn0 = new OleDbConnection(strconn);
cn0.Open();
string mysql = "select * from srname ";
//SqlCommand cm = new SqlCommand(mysql, cn0);
//SqlDataReader dr = cm.ExecuteReader();
OleDbCommand cm = new OleDbCommand(mysql,cn0);
OleDbDataReader dr = cm.ExecuteReader();
while (dr.Read())
{
drp.Items.Add(new ListItem(dr["sname"].ToString(), dr["snid"].ToString()));
}
cn0.Close();
}
}
protected void charu_Click(object sender, EventArgs e)
{
string strconn = connstring + Server.MapPath("csc.mdb");
OleDbConnection cn0 = new OleDbConnection(strconn);
cn0.Open();
String intext = drp.SelectedItem.Value.ToString();
string mysql = "insert into ss(ssvalue) values('"+intext+"')";
OleDbCommand cm = new OleDbCommand(mysql,cn0);
cm.ExecuteNonQuery();
Response.Redirect("RoomAdd.aspx");
}
}
这是个下拉菜单插入数据库VALUE值的例子
可他提示出问题"未将对象引用设置到对象的实例" 请大家看看 很苦恼
[此贴子已经被作者于2007-5-22 20:00:18编辑过]