rachayita jaiswal

rachayita jaiswal

  • NA
  • 217
  • 106.3k

MySql Stored Procedure in ASP.Net

Aug 28 2013 7:39 AM
Hi,

I have created function - 

public bool InsertORUpdateData(string SP, string action, string id, string str1, string str2, string str3, string str4, string str5, string str6, string str7, string str8, string str9, string str10, string str11, string str12, string str13, string str14, string str15, string str16)
    {
        bool value = false;
        strcon.Open();
        try
        {            
            MySqlCommand cmd = new MySqlCommand();
            MySqlDataAdapter ad = new MySqlDataAdapter();
            cmd.Connection = strcon;
            cmd.CommandText = SP;
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("_value1", action);
            cmd.Parameters.AddWithValue("_value2", id);
            cmd.Parameters.AddWithValue("_value3", str1);
            cmd.Parameters.AddWithValue("_value4", str2);
            cmd.Parameters.AddWithValue("_value5", str3);
            cmd.Parameters.AddWithValue("_value6", str4);
            cmd.Parameters.AddWithValue("_value7", str5);
            cmd.Parameters.AddWithValue("_value8", str6);
            cmd.Parameters.AddWithValue("_value9", str7);
            cmd.Parameters.AddWithValue("_value10", str8);
            cmd.Parameters.AddWithValue("_value11", str9);
            cmd.Parameters.AddWithValue("_value12", str10);
            cmd.Parameters.AddWithValue("_value13", str11);
            cmd.Parameters.AddWithValue("_value14", str12);
            cmd.Parameters.AddWithValue("_value15", str13);
            cmd.Parameters.AddWithValue("_value16", str14);
            cmd.Parameters.AddWithValue("_value17", str15);
            cmd.Parameters.AddWithValue("_value18", str16);
            cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
        }
        catch (Exception ex)
        {
            GetErrorFile("InsertORUpdateData Function", ex.Message);
        }
        finally
        {
            strcon.Close();
            value = true;
        }
        return value;
    } 

my stored procedure is - 

-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_AssetDetails`(_value1 varchar(10),
 _value2 varchar(10),
 _value3 varchar(100),
 _value4 varchar(50),
 _value5 varchar(50),
 _value6 varchar(50),
 _value7 varchar(50),
 _value8 varchar(50),
 _value9 varchar(50),
 _value10 varchar(50),
 _value11 varchar(150),
 _value12 varchar(20),
 _value13 varchar(20),
 _value14 varchar(50),
 _value15 varchar(50),
 _value16 varchar(150),
 _value17 varchar(50))
BEGIN
if _value1 = 'Select' then
select AssetType,Brand,Model,Vendor,PurchaseDate from m_asset;
end if;
END

and my code behind is - 

 bool updatemode = Convert.ToBoolean(txt_assetupdatemode.Text);
                bool assetvalue = obj_db.InsertORUpdateData("SP_AssetDetails", "Insert", "", "a00002", txt_assetdesc.Text, ddl_assettype.Text.Trim(), txt_assetbrand.Text, ddl_assetloc.SelectedValue, txt_assetmodel.Text, txt_assetserialno.Text, ddl_assetstatus.SelectedValue, ddl_assetcondition.SelectedValue, ddl_assetVendor.SelectedValue, txt_assetPprice.Text, txt_assetMvalue.Text, txt_assetPdate.Text, txt_assetWdate.Text, txt_assetnote.Text, "");
                if (assetvalue == true)
                {
                    lbl_asseterror.Text = "Asset Details saved successfully!";
                    LoadAssetData();
                }

My problem is - In my SP i didn't define Insert Query (It should be like = > _value1 = 'Insert')
but still it is not throwing any error like "in SP _value1 = insert" is missing ..........."
it is showing data saved successfully.......

Is anything wrong in my code?
Please tell me i am trying for a long time but did't get....

Answers (7)