AddStudent.aspx
<form id="form1" runat="server">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td >
<asp:Label ID="lblName" runat="server">名字</asp:Label>
</td>
<td >
<asp:TextBox ID="tbName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td >
<asp:Label ID="lblImg" runat="server">缩略图</asp:Label>
</td>
<td >
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
<tr>
<td>
内容简介
</td>
<td>
<asp:TextBox ID="tbContext" runat="server" Height="100px" MaxLength="10000" Rows="20" TextMode="MultiLine" Width="220px"></asp:TextBox>
</td>
</tr>
<tr>
<td >
<asp:Label ID="lblCategories" runat="server">类别</asp:Label>
</td>
<td >
<asp:RadioButton ID="rd1" runat="server" Text="优秀" GroupName="rd" />
<asp:RadioButton ID="rd2" runat="server" Text="精英" GroupName="rd" />
</td>
</tr>
<tr>
<td >
<asp:Button ID="btnOK" runat="server" Text="提交" OnClick="btnOK_Click" />
</td>
</tr>
</table>
<div>
</div>
</form>
数据库表
create table HT_U_AddStudent
(
ID int primary key identity(1,1),
StuName nvarchar(50) not null,
Img nvarchar(200) not null,
Context varchar(1000),
Categories bit default 1,
IsTop int not null
)
不知道你有没有用三层,所以就写这样了。
public class Student
{
private int studentid;
public int Studentid
{
get { return studentid; }
set { studentid = value; }
}
private string studentno;
public string Studentno
{
get { return studentno; }
set { studentno = value; }
}
private string studentname;
public string Studentname
{
get { return studentname; }
set { studentname = value; }
}
private string gender;
public string Gender
{
get { return gender; }
set { gender = value; }
}
private DateTime birthday;
public DateTime Birthday
{
get { return birthday; }
set { birthday = value; }
}
private int classid;
public int Classid
{
get { return classid; }
set { classid = value; }
}
private int status;
public int Status
{
get { return status; }
set { status = value; }
}
private string remark;
public string Remark
{
get { return remark; }
set { remark = value; }
}
}
下面的是获取界面输入的值:
namespace student
{
Student stu = new Student();
private void btnCreate_Click(object sender, EventArgs e)
{
stu.Studentname = this.txtName.Text;
stu.Studentid = Convert.ToInt32(this.txtStudentID.Text);
stu.Studentno = this.txtstudentNo.Text;
stu.Gender = this.cobSex.Text;
stu.Birthday = Convert.ToDateTime(this.dateTimePicker1.Text);
stu.Classid = Convert.ToInt32(this.cobClass.SelectedValue.ToString());
stu.Remark = this.txtRemark.Text;
int count = stuInsert(stu);
if (count > 0)
{
MessageBox.Show("添加成功!");
}
else
{
MessageBox.Show("添加失败!");
}
}
//插入数据库的方法(可以用存储过程)
public int stuInsert(Student stu)
{
con = new SqlConnection("server=WWW-9E99F2AB2EA\\MYSERVER2005;database=school;uid=sa;pwd=pengxue");
con.Open();
comm = new SqlCommand("insert into Student(StudentID,StudentNo,StudentName,Gender,Birthday,ClassId,status,remark) values(@StudentID,@StudentNo,@StudentName,@Gender,@Birthday,@classId,@status,@remark)", con);
comm.Parameters.Add("@StudentID", SqlDbType.Int).Value=stu.Studentid;
comm.Parameters.Add("@studentNo",SqlDbType.VarChar).Value=stu.Studentno;
comm.Parameters.Add("@StudentName", SqlDbType.VarChar).Value=stu.Studentname;
comm.Parameters.Add("@Gender", SqlDbType.VarChar).Value=stu.Gender;
comm.Parameters.Add("@Birthday", SqlDbType.DateTime).Value=stu.Birthday;
comm.Parameters.Add("@ClassId", SqlDbType.Int).Value=stu.Classid;
comm.Parameters.Add("@status",SqlDbType.Int).Value=1;
comm.Parameters.Add("@remark", SqlDbType.VarChar).Value=stu.Remark;
int i = comm.ExecuteNonQuery();
con.Close();
return i;
}
}
insert into 表名values字段值
例如:
nInsert into student(student_id,student_name,department) values(“070011”,”张三”,”公共关系”);