|
-
February 4th, 2008, 04:58 AM
#1
Insert multiple times
ASP.NET 2.0 Database SQLServer2000
Dear All,
Im beginner.
i got a problem when i press the SAVE button again and again then my code save this data in the database multiple times.
How i can control this problem i want just one time save when i press the save button. Im using stored procedure
Here is my code.
===========
Default.aspx
===========
if (Session["sysid"] == null)
{
string sysid = txtSystemId.Text;
string objName = txtObjectName.Text;
string formReport = "";
if (rdoReport.Checked == true)
{ formReport = "R"; }
else if (rdoForm.Checked == true)
{ formReport = "F"; }
string ReportQuery = txtReportQuery.Text;
//TextBox ReportForm for ReportName
string ReportForm = txtReportName.Text;
string ReportTitle = txtReportTitle.Text;
string OrderByClause = txtOrderByClause.Text;
string lstOdrByClause = "";
char swPrtCrit = '0';
if (ChkBox1showPrintCriteria.Checked == true)
{ swPrtCrit = '1'; }
else if (ChkBox1showPrintCriteria.Checked == true)
{ swPrtCrit = '0'; }
//UPDATE PASSING PARAMETERS
obj._insert(sysid, objName, formReport, ReportQuery, ReportForm, ReportTitle, OrderByClause, lstOdrByClause, swPrtCrit);
}
===========
MainPage.aspx
===========
public void _insert(string sysid, string objName, string formReport, string rptQry, string ReportForm, string rptTitle, string OdrByClause, string lstOdrByClause, char PrtCrit)
{
SqlCommand sqlcomm = sqlconn.CreateCommand();
sqlcomm.CommandType = CommandType.Text;
string spname = "Execute Sp_AllQuery_Insert " + "'" + sysid + "'" + "," + "'" + objName + "'" + "," + "'" + formReport + "'" + "," + "'" + rptQry + "'" + "," + "'" + ReportForm + "'" + "," + "'" + rptTitle + "'" + "," + "NULL" + "," + "NULL" + "," + "'" + PrtCrit + "'" + "";
sqlcomm.CommandText = spname;
sqlconn.Open();
int cnt = sqlcomm.ExecuteNonQuery();
try
{
if (cnt > 0)
{
//Console.WriteLine("Insert Successfully".ToString());
}
else
{
//Console.WriteLine("Insert Fail".ToString());
}
sqlconn.Close();
}
catch (Exception e)
{
sqlconn.Close();
}
}
-
February 4th, 2008, 07:51 AM
#2
Re: Insert multiple times
Please use the code tags for displaying your code... It makes easier for the people to read it...
You can disable the SAVE button once the user click on it.
OR
clear/reset all the input fields when user clicks on the SAVE button. And if user clicks on SAVE button for second time, show the message... such as "Input fields cannot be left blank" or something else you prefer...
Last edited by MMH; February 4th, 2008 at 07:54 AM.
Regards,
MMH
Rate my post if you find it usefull. 
-
February 4th, 2008, 08:15 AM
#3
Re: Insert multiple times
thanks MMH,
its working now :>. And i will use tags in my code. thanks for the help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|