SQL replacement program of asp.net on Web Page
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Repair_data.aspx.cs" Inherits = "admin_Repair_data" ValidateRequest = "false" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: TextBox ID = "TextBox1" runat = "server" Width = "597px"> </asp: TextBox>
<Asp: Button ID = "Button1" runat = "server" OnClick = "button#click" Text = "fixed"/> <br/>
<Br/>
Progress: <br/>
<Asp: Literal ID = "Literal1" runat = "server"> </asp: Literal> </div>
</Form>
</Body>
</Html>
Cs files
Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. IO;
Using System. Text. RegularExpressions;
Public partial class admin_Repair_data: System. Web. UI. Page
{
My_basic my_ B = new my_basic ();
My_conn my_c = new my_conn ();
Protected void Page_Load (object sender, EventArgs e)
{
If (! Page. IsPostBack)
{
}
}
Protected void button#click (object sender, EventArgs e)
{
DataTable dt = my_c.GetTable ("SELECT name, id, crdate, refdate FROM sysobjects WHERE xtype = 'U' and objectproperty (id, 'ismsshipped ') = 0 ");
For (int I = 0; I <dt. Rows. Count; I ++)
{
DataTable dt1 = my_c.GetTable ("SELECT Name, xtype FROM SysColumns WHERE id = Object_Id ('" + dt. rows [I] ["name"]. toString () + "')");
String t1 = "";
For (int j = 0; j <dt1.Rows. Count; j ++)
{
If (dt1.Rows [j] ["xtype"]. toString () = "231" | dt1.Rows [j] ["xtype"]. toString () = "99 ")
{
If (t1 = "")
{
T1 = dt1.Rows [j] ["Name"]. ToString ();
}
Else
{
T1 = t1 + "|" + dt1.Rows [j] ["Name"]. ToString ();
}
}
}
If (t1! = "")
{
DataTable dt2 = my_c.GetTable ("select id," + t1.Replace ("|", ",") + "from" + dt. rows [I] ["name"]. toString () + "");
For (int h = 0; h <dt2.Rows. Count; h ++)
{
String SQL = "update" + dt. Rows [I] ["name"]. ToString () + "set ";
String [] aa = t1.Split ('| ');
For (int l = 0; l <aa. Length; l ++)
{
If (l = 0)
{
SQL = SQL + "" + aa [l]. toString () + "= '" + dt2.Rows [h] [aa [l]. toString ()]. toString (). replace (my_ B .c_string (this. textBox1.Text), "") + "'";
}
Else
{
SQL = SQL + "," + aa [l]. toString () + "= '" + dt2.Rows [h] [aa [l]. toString ()]. toString (). replace (my_ B .c_string (this. textBox1.Text), "") + "'";
}
}
SQL = SQL + "where id =" + dt2.Rows [h] ["id"]. ToString ();
// Response. Write (SQL );
// Response. End ();
My_c.genxin (SQL );
}
}
}
Literal1.Text = "finished ";
}
}