求助各位大神——C#做web的时候出现了问题
程序代码:using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Data.SqlTypes;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
con.ConnectionString = @"Data Source=EZCHPLXFN2SMP6I;Initial Catalog=C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\桌面\WEB技术\数据库\APP_DATA\STUDENT.MDF;Integrated Security=True";
con.Open();
cmd.Connection = con;
= "insert into students values(@stuid,@name,@sex,@birthday,@department,@totalscore)";
SqlParameter stuid=new SqlParameter("@stuid",SqlDbType.NVarChar,10);
cmd.Parameters.Add(stuid);
SqlParameter name=new SqlParameter("@name",SqlDbType.NVarChar,20);
cmd.Parameters.Add(name);
SqlParameter sex=new SqlParameter("@sex",SqlDbType.Bit);
cmd.Parameters.Add(sex);
SqlParameter birthday = new SqlParameter("@birthday", SqlDbType.SmallDateTime);
cmd.Parameters.Add(birthday);
cmd.Parameters.Add(new SqlParameter("@department",SqlDbType.NVarChar,20));
cmd.Parameters.Add(new SqlParameter("@totalscore", SqlDbType.Int));
cmd.Parameters["@stuid"].Value=Request.Form["studentid"];
cmd.Parameters["@name"].Value=Request.Form["name"];
if (sex1.Checked = true)
cmd.Parameters["@sex"].Value = true;
else
cmd.Parameters["@sex"].Value = false;
cmd.Parameters["@birthday"].Value=Request.Form["@birthday"];
cmd.Parameters["@department"].Value=Request.Form["@department"];
cmd.Parameters["@totalscore"].Value=int.Parse(Request.Form["@totalscore"]);
cmd.ExecuteNonQuery();
GridView1.DataBind();
con.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
stuid.Text = "";
name.Text = "";
sex1.Checked =false;
sex2.Checked = false;
birthday.Text = "";
department.Text = "";
totalscore.Text = "";
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
SqlCommand cmd=new SqlCommand();
con.ConnectionString=@"Data Source=EZCHPLXFN2SMP6I;Initial Catalog=C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\桌面\WEB技术\数据库\APP_DATA\STUDENT.MDF;Integrated Security=True";
con.Open();
cmd.Connection=con;
"delete students where studentid='"+stuid.Text+"'";
cmd.ExecuteNonQuery();
GridView1.DataBind();
con.Close();
}
}
[ 本帖最后由 好北 于 2013-6-24 21:38 编辑 ]









