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();
}
}
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();
}
}