CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    Posts
    7

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

  2. #2
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    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.

  3. #3
    Join Date
    Dec 2007
    Posts
    7

    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
  •  





Click Here to Expand Forum to Full Width

Featured