으로 업데이트하십시오. ASP의 텍스트 상자를 통해 데이터베이스의 값을 편집하려고합니다.데이터베이스의 값을 텍스트 상자
먼저 데이터베이스에서 값을 검색하여 사용자가 이전 값을 볼 수 있도록 양식의 텍스트 상자 값 속성에 값을 설정합니다.
이제 그는 동일한 텍스트 상자에 새 값을 입력하고 업데이트를 클릭하면 새 값이 데이터베이스에 업데이트되어야합니다.
내가 그 새로운 가치를 얻으려면 무엇을해야하는지 알 수 있습니까? 양식 제출시기 ????
코드 :
protected void Button2_Click(object sender, EventArgs e)
{
string MachineGroupName = TextBox2.Text;
string MachineGroupDesc = TextBox3.Text;
int TimeAdded = DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second;
if (MachineGroupName == "" || MachineGroupDesc == "")
{
Label2.Text = ("Please ensure all fields are entered");
Label2.Visible = true;
}
else
{
System.Data.SqlClient.SqlConnection dataConnection = new SqlConnection();
dataConnection.ConnectionString =
@"Data Source=JAGMIT-PC\SQLEXPRESS;Initial Catalog=SumooHAgentDB;Integrated Security=True";
System.Data.SqlClient.SqlCommand dataCommand = new SqlCommand();
dataCommand.Connection = dataConnection;
//tell the compiler and database that we're using parameters (thus the @first, @last, @nick)
dataCommand.CommandText = ("UPDATE [MachineGroups] SET ([MachineGroupName][email protected],[MachineGroupDesc][email protected],[TimeAdded][email protected]) WHERE ([MachineGroupID]= @node)");
//add our parameters to our command object
dataCommand.Parameters.AddWithValue("@MachineGroupName", MachineGroupName);
dataCommand.Parameters.AddWithValue("@MachineGroupDesc", MachineGroupDesc);
dataCommand.Parameters.AddWithValue("@TimeAdded", TimeAdded);
dataConnection.Open();
dataCommand.ExecuteNonQuery();
dataConnection.Close();
}
이것은 질문과는 관련이 없지만 SqlCommand 개체를 처리하는 것을 잊지 마십시오. –
또한 다른 페이지에서 전달 된 쿼리 문자열에서 노드 값을 얻고 있습니다. 잘 작동합니다. 페이지로드 이벤트에 이 있습니다. string node = Request.QueryString [ "node"]; 이렇게 노드 값이 – user175084
이되면 예외가 발생합니까? 당신의 코드가 좀 괜찮아 보입니다. – Konstantinos