最近突然接到单位一个改动的小项目,一个小小的报名系统,需要用到asp.net技术,之前只是对 该技术略有耳闻,不过有网页编程的基础,就好搞许多了到目前位置用到一下技术:
1、连接数据库,这个事最基本的,用的是access数据库,数据库验证方式在web.config目录写死:
<connectionStrings> <add name="ssl" connectionString="provider=microsoft.jet.oledb.4.0;data source=D:\XXX\XXX.mdb;"></add> </connectionStrings>
2、连接数据库如下写法:(包括读取,插入等)
string str = ConfigurationManager.ConnectionStrings["ssl"].ConnectionString; OleDbConnection conn = new OleDbConnection(str); //判断考生是否已经选择报考点 string condition_insert_addr ="select ex_XXX_province from ex_district where exer_id=" + Session["StuID"]; //判断考生信息是否已经写入报考信息数据表 string condition_inser_bminfo="select bk_XXX_id from baoming_info where bk_exer_id=" + Session["StuID"]; //插入报考点信息 string insert_region = "insert into ex_XXX(ex_dis_Name,ex_dis_province,ex_dis_city,ex_dis_town,exer_id) values(" +"'hello','"+bm_province + "','" + bm_city + "','" + bm_country + "'," + Session["StuID"] + ")"; OleDbCommand cmd = new OleDbCommand(condition_insert_addr, conn);
conn.Open();
OleDbDataReader rdr ;
rdr= cmd.ExecuteReader();
if (rdr.Read() == false)
{
OleDbCommand cmd2 = new OleDbCommand(insert_region, conn);
cmd2.ExecuteNonQuery();
}
else
{
string updater_region = "update ex_XXXX set ex_dis_province=" + "'" + bm_province + "',ex_dis_city='" + bm_city + "',ex_dis_town='" + bm_country + "'" + "where exer_id=" + Session["StuID"];
OleDbCommand cmd2 = new OleDbCommand(updater_region, conn);
cmd2.ExecuteNonQuery();
}
conn.close();
//读取字段
//while (rdr.Read())
//{
//TextBox1.Text = rdr["name"].ToString();//name
//TextBox2.Text = rdr["sex"].ToString();//sex
//TextBox3.Text = rdr["st_adr"].ToString();//bir_addr
//birth_date.Text = rdr["cs_date"].ToString();//bir_date
//}
3、从后台读取jquery生成的select,DropList控件的值:
<div id="ChinaArea"> <asp:DropDownList ID="province" runat="server"></asp:DropDownList> <asp:DropDownList ID="city" runat="server"></asp:DropDownList> <asp:DropDownList ID="country" runat="server"></asp:DropDownList> <asp:HiddenField runat="server" ID="Tprovince" /> <asp:HiddenField runat="server" ID="TCity" /> <asp:HiddenField runat="server" ID="TCounty" /> </div>
后台读取,下拉单的文本,不是value:
string bm_province = Tprovince.Value;
string bm_city = TCity.Value;
string bm_country = TCounty.Value;
/*读取直接生成的下拉菜单的值比较简单:string profess_pro=DropDownList1.SelectedItem.Text;*/
4、还有诸多问题,遇到在蛋疼整理,哇咔咔,下班回家吃饭喽~~~~