我是一个ASP。NET的初学着,遇到了这么一个问题,各位高手帮忙解决一下
自己设计了一个数据库
库名是:user
里面有一张表:users,其中有“姓名,性别,职业,爱好”这四个字段,都是varchar类型的,姓名是主键
然后是自己设计了一个页面,上面也是“姓名,性别,职业,爱好”这四项,具体的HTML代码如下:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Example_olpy.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblName" style="Z-INDEX: 100; LEFT: 208px; POSITION: absolute; TOP: 48px" runat="server">姓名</asp:Label>
<asp:CheckBox id="cboMuice" style="Z-INDEX: 113; LEFT: 416px; POSITION: absolute; TOP: 192px"
runat="server" Text="音乐"></asp:CheckBox>
<asp:CheckBox id="cboFootball" style="Z-INDEX: 112; LEFT: 536px; POSITION: absolute; TOP: 192px"
runat="server" Text="足球"></asp:CheckBox>
<asp:Label id="lblAihao" style="Z-INDEX: 108; LEFT: 208px; POSITION: absolute; TOP: 192px"
runat="server">爱好</asp:Label>
<asp:RadioButton id="radGanderF" style="Z-INDEX: 106; LEFT: 424px; POSITION: absolute; TOP: 96px"
runat="server" Text="女" GroupName="Chooser"></asp:RadioButton>
<asp:Label id="lblGander" style="Z-INDEX: 103; LEFT: 208px; POSITION: absolute; TOP: 96px"
runat="server">性别</asp:Label>
<asp:Label id="lblZhiye" style="Z-INDEX: 102; LEFT: 208px; POSITION: absolute; TOP: 144px"
runat="server">职业</asp:Label>
<asp:Label id="lblMessage" style="Z-INDEX: 101; LEFT: 208px; POSITION: absolute; TOP: 312px"
runat="server" Width="432px" Height="216px"></asp:Label>
<asp:TextBox id="txtName" style="Z-INDEX: 104; LEFT: 296px; POSITION: absolute; TOP: 48px" runat="server"></asp:TextBox>
<asp:RadioButton id="radGanderM" style="Z-INDEX: 105; LEFT: 296px; POSITION: absolute; TOP: 96px"
runat="server" Text="男" GroupName="Chooser"></asp:RadioButton>
<asp:DropDownList id="ddlZhiye" style="Z-INDEX: 107; LEFT: 296px; POSITION: absolute; TOP: 144px"
runat="server" Width="152px">
<asp:ListItem Value="IT" Selected="True">IT</asp:ListItem>
<asp:ListItem Value="建筑">建筑</asp:ListItem>
<asp:ListItem Value="医生">医生</asp:ListItem>
</asp:DropDownList>
<asp:Button id="butSmbit" style="Z-INDEX: 109; LEFT: 536px; POSITION: absolute; TOP: 248px"
runat="server" Text="提交"></asp:Button>
<asp:CheckBox id="cboRun" style="Z-INDEX: 111; LEFT: 296px; POSITION: absolute; TOP: 192px" runat="server"
Text="跑步"></asp:CheckBox>
</form>
</body>
</HTML>
//----------------//还有。CS里面的代码如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Example_olpy
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblName;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Label lblZhiye;
protected System.Web.UI.WebControls.Label lblGander;
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.RadioButton radGanderM;
protected System.Web.UI.WebControls.RadioButton radGanderF;
protected System.Web.UI.WebControls.DropDownList ddlZhiye;
protected System.Web.UI.WebControls.Label lblAihao;
protected System.Web.UI.WebControls.Button butSmbit;
protected System.Web.UI.WebControls.CheckBox cboRun;
protected System.Web.UI.WebControls.CheckBox cboFootball;
protected System.Web.UI.WebControls.CheckBox cboMuice;
private String strGander="";
private String strZhiye="";
private String strAihao="";
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.cboMuice.CheckedChanged += new System.EventHandler(this.cboMuice_CheckedChanged);
this.cboFootball.CheckedChanged += new System.EventHandler(this.cboFootball_CheckedChanged);
this.radGanderF.CheckedChanged += new System.EventHandler(this.radGanderF_CheckedChanged);
this.radGanderM.CheckedChanged += new System.EventHandler(this.radGanderM_CheckedChanged);
this.ddlZhiye.SelectedIndexChanged += new System.EventHandler(this.ddlZhiye_SelectedIndexChanged);
this.butSmbit.Click += new System.EventHandler(this.butSmbit_Click);
this.cboRun.CheckedChanged += new System.EventHandler(this.cboRun_CheckedChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void radGanderM_CheckedChanged(object sender, System.EventArgs e)
{
strGander="男";
}
private void radGanderF_CheckedChanged(object sender, System.EventArgs e)
{
strGander="女";
}
private void ddlZhiye_SelectedIndexChanged(object sender, System.EventArgs e)
{
strZhiye=ddlZhiye.SelectedItem.Text;
}
private void cboRun_CheckedChanged(object sender, System.EventArgs e)
{
if(strAihao=="")
strAihao=strAihao+cboRun.Text;
else
strAihao=strAihao+","+cboRun.Text;
}
private void cboMuice_CheckedChanged(object sender, System.EventArgs e)
{
if(strAihao=="")
strAihao=strAihao+cboMuice.Text;
else
strAihao=strAihao+","+cboMuice.Text;
}
private void cboFootball_CheckedChanged(object sender, System.EventArgs e)
{
if(strAihao=="")
strAihao=strAihao+cboFootball.Text;
else
strAihao=strAihao+","+cboFootball.Text;
}
private void butSmbit_Click(object sender, System.EventArgs e)
{
lblMessage.Text=lblMessage.Text+"[姓名:"+txtName.Text+"] ";
lblMessage.Text=lblMessage.Text+"[性别:"+strGander+"] ";
lblMessage.Text=lblMessage.Text+"[职业:"+strZhiye+"] ";
lblMessage.Text=lblMessage.Text+"[爱好:"+strAihao+"] ";
}
}
}
请问一下各位高手,怎样才能把用户写在显示窗体上的“姓名,性别,职业,爱好”添加到我设计的那个数据库的表里面,具体的代码是什么?还有具体的数据库连接代码(这些代码都要写在那)?