简体   繁体   English

更改/编辑插入表中的数据

[英]Alter/edit data inserted into table

I've created a login and register page where people can login or register if they are new, and when they are logged in they have the opportunity to post information much like what i'm doing now... this info goes into a list view in the page that appears after they logged in 我创建了一个登录和注册页面,人们可以在其中登录或注册(如果他们是新用户),并且当他们登录时,他们有机会像我现在所做的那样发布信息...此信息将进入列表他们登录后出现的页面中的视图

Now i've tested it and it works, problem is I made lots of mistakes, now I want to edit it by making an edit page with the same controls as the post page but how do alter the info I posted? 现在我已经对其进行了测试,并且可以正常工作,问题是我犯了很多错误,现在我想通过制作一个具有与发布页面相同的控件的编辑页面来对其进行编辑,但是如何更改我发布的信息?

code for posting info 发布信息的代码

    protected void Button1_Click(object sender, EventArgs e)
{
    string answer = "NO";
    string strcon = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\VC_temps.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
    SqlConnection con = new SqlConnection(strcon);

    SqlCommand com = new SqlCommand("Store-Jobs", con);
    com.CommandType = CommandType.StoredProcedure;
    SqlParameter p1 = new SqlParameter("Job", TextBox1.Text);
    SqlParameter p2 = new SqlParameter("JobType", DropDownList1.Text);
    SqlParameter p3 = new SqlParameter("StartDate", TextBox3.Text);
    SqlParameter p4 = new SqlParameter("Time", TextBox2.Text);
    SqlParameter p5 = new SqlParameter("JobID", TextBox1.Text.Substring(3).ToUpper());
    SqlParameter p6 = new SqlParameter("CompanyID", Session["CompID"]);
    SqlParameter p7 = new SqlParameter("PoistionFilled", answer);
    SqlParameter p8 = new SqlParameter("Description", TextBox4.Text);
    com.Parameters.Add(p1);
    com.Parameters.Add(p2);
    com.Parameters.Add(p3);
    com.Parameters.Add(p4);
    com.Parameters.Add(p5);
    com.Parameters.Add(p6);
    com.Parameters.Add(p7);
    com.Parameters.Add(p8);
    con.Open();
    com.ExecuteNonQuery();
    Labelinfo.Text = "Post successful.";
}

Load in the textboxes the data by ID and then handle the update in SP of Store-Jobs. 按ID在文本框中加载数据,然后在Store-Jobs SP中处理更新。 When the ID is greater then 0 do an update otherwise do an insert. 当ID大于0时,执行更新,否则插入。

SQL Example; SQL示例;

If @ID > 0
'Update Store-Jobs
Else
'Insert Store Jobs

C# C#

SqlCommand com = new SqlCommand("Store-Jobs", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("ID", Request.QueryString("ID") == Null ? Request.QueryString("ID") : 0);    
com.Parameters.AddWithValue("Job", TextBox1.Text);
com.Parameters.AddWithValue("JobType", DropDownList1.Text);
com.Parameters.AddWithValue("StartDate", TextBox3.Text);
com.Parameters.AddWithValue("Time", TextBox2.Text);
com.Parameters.AddWithValue("JobID", TextBox1.Text.Substring(3).ToUpper());
com.Parameters.AddWithValue("CompanyID", Session["CompID"]);
com.Parameters.AddWithValue("PoistionFilled", answer);
com.Parameters.AddWithValue("Description", TextBox4.Text);
con.Open();
com.ExecuteNonQuery();
Labelinfo.Text = "Post successful.";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM