필자는 버튼을 한 번 클릭하여 2 개의 SQL 쿼리를 전달하려고 시도 했으므로 아래에 표시된 것처럼 ive가 수행하려고 시도한 것이지만 작동하지 않습니다 .... 감사합니다. 사전onclick C에서 두 메서드 호출 #
그래서 이것은 앞의 코드
<asp:Button ID="btnWedRecInsert" runat="server" Text="Insert" OnClick="btnWedRecInsert_Click1; btnWedRecInsert_Click2;" />
코드 뒤에
protected void btnWedRecInsert_Click1(object sender, EventArgs e)
{
string Function = ddlFunction.Text;
string FunctionDate = txtFunctionDate.Text;
string FunctionTime = ddlFunctionTime.Text;
string groomName = txtGroomName.Text;
string groomFatherName = txtGroomFatherName.Text;
string groomAge = txtGroomAge.Text;
string groomPhone = txtGroomPhone.Text;
string groomAddress = txtGroomAddress.Text;
string brideName = txtBrideName.Text;
string brideFatherName = txtBrideFatherName.Text;
string brideAge = txtBrideAge.Text;
string bridePhone = txtBridePhone.Text;
string brideAddress = txtBrideAddress.Text;
string registerName = txtRegisterName.Text;
string registerPhone = txtRegisterPhone.Text;
string registerAddress = txtRegisterAddress.Text;
string referenceName = txtReferenceName.Text;
string referencePhone = txtReferencePhone.Text;
string referenceAddress = txtReferenceAddress.Text;
string connString = ConfigurationManager.ConnectionStrings["MandapamDatabase"].ConnectionString;
OleDbConnection connection = new OleDbConnection(connString);
string insertQuery = "INSERT INTO wedding(RegisteredDate, Function, FunctionDate, FunctionTime, groomName, groomFatherName, groomAge, groomPhone, groomAddress, brideName, brideFatherName, brideAge, bridePhone, brideAddress, registerName, registerPhone, registerAddress, referenceName, referencePhone, referenceAddress) VALUES(@Date, @Function, @FunctionDate, @FunctionTime, @groomName, @groomFatherName, @groomAge, @groomPhone, @groomAddress, @brideName, @brideFatherName, @brideAge, @bridePhone, @brideAddress, @registerName, @registerPhone, @registerAddress, @referenceName, @referencePhone, @referenceAddress) ";
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = insertQuery;
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@Date", DateTime.Now.Date);
command.Parameters.AddWithValue("@Function", Function);
command.Parameters.AddWithValue("@FunctionDate", FunctionDate);
command.Parameters.AddWithValue("@FunctionTime", FunctionTime);
command.Parameters.AddWithValue("@groomName", groomName);
command.Parameters.AddWithValue("@groomFatherName", groomFatherName);
command.Parameters.AddWithValue("@groomAge", groomAge);
command.Parameters.AddWithValue("@groomPhone", groomPhone);
command.Parameters.AddWithValue("@groomAddress", groomAddress);
command.Parameters.AddWithValue("@brideName", brideName);
command.Parameters.AddWithValue("@brideFatherName", brideFatherName);
command.Parameters.AddWithValue("@brideAge", brideAge);
command.Parameters.AddWithValue("@bridePhone", bridePhone);
command.Parameters.AddWithValue("@brideAddress", brideAddress);
command.Parameters.AddWithValue("@registerName", registerName);
command.Parameters.AddWithValue("@registerPhone", registerPhone);
command.Parameters.AddWithValue("@registerAddress", registerAddress);
command.Parameters.AddWithValue("@referenceName", referenceName);
command.Parameters.AddWithValue("@referencePhone", referencePhone);
command.Parameters.AddWithValue("@referenceAddress", referenceAddress);
try
{
connection.Open();
command.ExecuteNonQuery();
lblMessage.Text = "Record inserted successfully";
}
catch (Exception ex)
{
lblMessage.Text = "Unable to insert record";
}
finally
{
connection.Close();
}
}
protected void btnWedRecInsert_Click2(object sender, EventArgs e)
{
string Function = ddlReception.Text;
string FunctionDate = txtReceptionDate.Text;
string FunctionTime = ddlReceptionTime.Text;
string groomName = txtGroomName.Text;
string groomFatherName = txtGroomFatherName.Text;
string groomAge = txtGroomAge.Text;
string groomPhone = txtGroomPhone.Text;
string groomAddress = txtGroomAddress.Text;
string brideName = txtBrideName.Text;
string brideFatherName = txtBrideFatherName.Text;
string brideAge = txtBrideAge.Text;
string bridePhone = txtBridePhone.Text;
string brideAddress = txtBrideAddress.Text;
string registerName = txtRegisterName.Text;
string registerPhone = txtRegisterPhone.Text;
string registerAddress = txtRegisterAddress.Text;
string referenceName = txtReferenceName.Text;
string referencePhone = txtReferencePhone.Text;
string referenceAddress = txtReferenceAddress.Text;
string connString = ConfigurationManager.ConnectionStrings["MandapamDatabase"].ConnectionString;
OleDbConnection connection = new OleDbConnection(connString);
string insertQuery = "INSERT INTO wedding(RegisteredDate, Function, ReceptionTime, FunctionDate, FunctionTime, groomName, groomFatherName, groomAge, groomPhone, groomAddress, brideName, brideFatherName, brideAge, bridePhone, brideAddress, registerName, registerPhone, registerAddress, referenceName, referencePhone, referenceAddress) VALUES(@Date, @Function, @FunctionDate, @FunctionTime, @groomName, @groomFatherName, @groomAge, @groomPhone, @groomAddress, @brideName, @brideFatherName, @brideAge, @bridePhone, @brideAddress, @registerName, @registerPhone, @registerAddress, @referenceName, @referencePhone, @referenceAddress) ";
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = insertQuery;
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@Date", DateTime.Now.Date);
command.Parameters.AddWithValue("@Function", Function);
command.Parameters.AddWithValue("@FunctionDate", FunctionDate);
command.Parameters.AddWithValue("@FunctionTime", FunctionTime);
command.Parameters.AddWithValue("@groomName", groomName);
command.Parameters.AddWithValue("@groomFatherName", groomFatherName);
command.Parameters.AddWithValue("@groomAge", groomAge);
command.Parameters.AddWithValue("@groomPhone", groomPhone);
command.Parameters.AddWithValue("@groomAddress", groomAddress);
command.Parameters.AddWithValue("@brideName", brideName);
command.Parameters.AddWithValue("@brideFatherName", brideFatherName);
command.Parameters.AddWithValue("@brideAge", brideAge);
command.Parameters.AddWithValue("@bridePhone", bridePhone);
command.Parameters.AddWithValue("@brideAddress", brideAddress);
command.Parameters.AddWithValue("@registerName", registerName);
command.Parameters.AddWithValue("@registerPhone", registerPhone);
command.Parameters.AddWithValue("@registerAddress", registerAddress);
command.Parameters.AddWithValue("@referenceName", referenceName);
command.Parameters.AddWithValue("@referencePhone", referencePhone);
command.Parameters.AddWithValue("@referenceAddress", referenceAddress);
try
{
connection.Open();
command.ExecuteNonQuery();
lblMessage.Text = "Record inserted successfully";
}
catch (Exception ex)
{
lblMessage.Text = "Unable to insert record";
}
finally
{
connection.Close();
}
}
하지만이 두 가지 버튼 클릭 이벤트를 .... 표시하지 1 .. 당신이'의 OnClick = 사용할 때 1 – BugFinder
이 오류가 던져 질 때 무슨 일이 있었는지 "btnWedRecInsert_Click1, btnWedRecInsert_Click2가;"'? –
이러한 클릭 이벤트는 다른 이벤트 또는 다른 이벤트를 트리거하는 단추와 같은 다른 곳에서 재사용됩니까? 어느 쪽이든 나는이 사건들의 논리를 그들 자신의 방법으로 추출 할 것을 제안 할 것이다. 그런 다음 각 이벤트 메서드는 적절한 메서드를 호출하는 한 줄을 가질 수 있으며 두 이벤트를 호출하는 다른 이벤트가 필요한 경우 추출 된 메서드를 모두 호출하는 새 이벤트 메서드를 만듭니다. – Chris