Click to See Complete Forum and Search --> : Insert multiple times


stringsinaction
February 4th, 2008, 03:58 AM
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();
}
}

MMH
February 4th, 2008, 06:51 AM
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...

stringsinaction
February 4th, 2008, 07:15 AM
thanks MMH,

its working now :>. And i will use tags in my code. thanks for the help.