locked
Insert Data into Mysql from Aspnet C# (sql stored procedure ) RRS feed

  • Question

  • User53274426 posted

    Hi Everybody,

    I have installe Mysql and its Connector on my machine .. And have created sql stored procedure to Insert Data like Name, age, city and so on

    How can i defend connection in asp.net kode and call sql stored procedure  to insert... IN a VERy Simpel way!

    I have seen many examples on internet...  Thye use Dataobject Souce and so on.. i WANT it in SIMPEL way

    Plzz help my 

    Thursday, October 27, 2011 4:23 PM

All replies

  • User-608283337 posted

    refer the link below. It's simple and step by step way to do what you are looking for. hope this helps.

     

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insertcommand.aspx

     

     

    Thursday, October 27, 2011 4:28 PM
  • User-1199946673 posted

    i WANT it in SIMPEL way

    If everything would be simple, anybody could be a professional web developer. ASP.NET makes a lot of things much more simple as it was before, but the only way to do this is when you're willing to learn, even if it is more difficult than you want....

    Thursday, October 27, 2011 4:31 PM
  • Thursday, October 27, 2011 8:37 PM
  • User53274426 posted


    Yes i have a connection to Database from Asp.net Cool


    But my problem is when i excute stored procedure direct om Mysql database, its working.

    CALL sp_FindesBrugeren_aL('Issssn@yes.dk' ,@AntalBruger);
    SELECT @AntalBruger;

    But then i excute it from asp.bet website.. its say there is error in my sq line one near email adressel:

    cmd.CommandText = "sp_FindesBrugeren_aL(@INEmai);";
    cmd.Parameters.AddWithValue("@INEmail",Tjekemail);

    Here the parameter "Tjekemail" is a mail adresse.

    Here is my stored procedure

    CREATE PROCEDURE sp_FindesBrugeren_aL
         (
       	IN INEmail  VARCHAR(300),
    		OUT AntalBruger int
     )
    BEGIN 
          SELECT count(*) FROM brugerinformation Where brugerinformation.Email = INEmail INTO AntalBruger; 
       END $$ 
    
    
    
    
    Maby i have to send the email adresse form asp.net website to mysql like yes 'ikkk@live.dk'
    BUT why i shuld add ' ' to this ?
    Friday, October 28, 2011 8:44 PM
  • User-448512826 posted
    Hi,

    change like.....

    cmd.CommandType = CommandType.StoredProcedure;

    cmd.CommandText = "sp_FindesBrugeren_aL";
    cmd.Parameters.AddWithValue("@INEmail",Tjekemail);

    Thanks...
    Friday, October 28, 2011 11:27 PM
  • User53274426 posted

    Hi,

    change like.....

    cmd.CommandType = CommandType.StoredProcedure;

    cmd.CommandText = "sp_FindesBrugeren_aL";
    cmd.Parameters.AddWithValue("@INEmail",Tjekemail);

    Thanks...

    I have tryed that. I Get one error like this :

    Parameter 'AntalBruger' not found in the collection.

    Saturday, October 29, 2011 4:45 AM
  • User-448512826 posted

    Parameter 'AntalBruger' not found in the collection.

    what is AntalBruger?

    why you use this...

    so you have to pass that variable also like @INEmail..

    like @INEmail you have to pass AntalBruger variable which you declare in your procedure...

    Thanks...

    Saturday, October 29, 2011 5:57 AM
  • User53274426 posted
    I have a stored presedure , where i send a email adresse. the sql count(*) the row and put count in AntalBruger. The database should giv me Antalbruger, its not a parameter i will send from asp. Net
    Saturday, October 29, 2011 7:23 AM
  • User-448512826 posted

    The database should giv me Antalbruger, its not a parameter


     OUT AntalBruger int--------what is it....?
    pass this variable in page like another variable.... 
    Thanks...
    Saturday, October 29, 2011 11:26 AM
  • User53274426 posted
    Well antalbruger is 0. If user dont exist already. Antalbruger is 1 if the user exust already
    Saturday, October 29, 2011 1:11 PM
  • User-448512826 posted

    Hi,

    you just pass it in your code ...

    if you no need to output then ok

    but you have to pass in code...

    Thanks...

    Saturday, October 29, 2011 2:37 PM