using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection myConn = GetConnection();
myConn.Open();
string yhbm1 = "select max(yhbm) as maxyhbm from [yhb]";
SqlCommand cmd = new SqlCommand(yhbm1, myConn);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("yhbm", typeof(System.Int32));
if (dr.Read())
{
DataRow row = dt.NewRow();
row["yhbm"] = dr["maxyhbm"].ToString();
dt.Rows.Add(row);
}
dr.Close();
string a = dt.Rows[0]["yhbm"].ToString();
int i = int.Parse(a) + 1;
this.TextBox1.Text = i.ToString();
myConn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection myConn = new SqlConnection();
myConn.ConnectionString="Data Source=CL-70F23EADBA24\\SQL_2005;Initial Catalog=yutao;Persist Security Info=True;User ID=sa;Password=123456";
//string insertStr = "insert into yhb(yhbm,yhmc,yhmm,yhbz) values ('" + TextBox1.Text + "','" +TextBox2.Text + "','" + TextBox3.Text + "','" +TextBox5.Text + "')";
string insertStr = "insert into yhb(yhmc,yhmm,yhbz) values ('" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox5.Text + "')";
SqlCommand myCmd = new SqlCommand(insertStr, myConn);
try
{
myConn.Open ();
myCmd.ExecuteNonQuery();
Label1.Text = "插入成功";
Response.Redirect("Default.aspx");
}
catch
{
Label1.Text = "插入失败";
}
finally
{
myConn.Close();
}
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string yhbm = GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
string yhmc = (GridView1.Rows[e.NewSelectedIndex].Cells[2]).Text.ToString();
string yhmm = (GridView1.Rows[e.NewSelectedIndex].Cells[3]).Text.ToString();
string yhbz = (GridView1.Rows[e.NewSelectedIndex].Cells[4]).Text.ToString();
TextBox1.Text = yhbm;
TextBox2.Text = yhmc;
TextBox3.Text = yhmm;
TextBox4.Text = yhmm;
TextBox5.Text = yhbz;
}
protected void Button2_Click(object sender, EventArgs e)
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection myConn = GetConnection();
myConn.Open();
string yhbm1 = "select max(yhbm) as maxyhbm from [yhb]";
SqlCommand cmd = new SqlCommand(yhbm1, myConn);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("yhbm", typeof(System.Int32));
if (dr.Read())
{
DataRow row = dt.NewRow();
row["yhbm"] = dr["maxyhbm"].ToString();
dt.Rows.Add(row);
}
dr.Close();
string a = dt.Rows[0]["yhbm"].ToString();
int i = int.Parse(a) + 1;
this.TextBox1.Text = i.ToString();
myConn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection myConn = new SqlConnection();
myConn.ConnectionString="Data Source=CL-70F23EADBA24\\SQL_2005;Initial Catalog=yutao;Persist Security Info=True;User ID=sa;Password=123456";
//string insertStr = "insert into yhb(yhbm,yhmc,yhmm,yhbz) values ('" + TextBox1.Text + "','" +TextBox2.Text + "','" + TextBox3.Text + "','" +TextBox5.Text + "')";
string insertStr = "insert into yhb(yhmc,yhmm,yhbz) values ('" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox5.Text + "')";
SqlCommand myCmd = new SqlCommand(insertStr, myConn);
try
{
myConn.Open ();
myCmd.ExecuteNonQuery();
Label1.Text = "插入成功";
Response.Redirect("Default.aspx");
}
catch
{
Label1.Text = "插入失败";
}
finally
{
myConn.Close();
}
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string yhbm = GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
string yhmc = (GridView1.Rows[e.NewSelectedIndex].Cells[2]).Text.ToString();
string yhmm = (GridView1.Rows[e.NewSelectedIndex].Cells[3]).Text.ToString();
string yhbz = (GridView1.Rows[e.NewSelectedIndex].Cells[4]).Text.ToString();
TextBox1.Text = yhbm;
TextBox2.Text = yhmc;
TextBox3.Text = yhmm;
TextBox4.Text = yhmm;
TextBox5.Text = yhbz;
}
protected void Button2_Click(object sender, EventArgs e)