Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET MySQL
Hello Friends,
 

i want to insert textbox value into database using store procedure.can any one help me??
 

 

Regards
Deepak
Posted 24-Jun-11 2:01am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Procedure in MySQL:
CREATE PROCEDURE insertToTable
(IN param1 CHAR(20))
BEGIN
  INSERT INTO table(field1) VALUES(param1)
END
 
Code in program:
MySqlCommand cmd = new MySqlCommand("insertToTable", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@param1", TextBox1.Text);
cmd.ExecuteNonQuery();
 
Ref: http://dev.mysql.com/doc/refman/5.5/en/connector-net-tutorials-intro.html#connector-net-tutorials-stored-procedures[^]
  Permalink  
Comments
guptaadeepak at 24-Jun-11 8:17am
   
i need some more help you code is working but i have problem on executenonquery i am post my code too plz help me
guptaadeepak at 24-Jun-11 8:31am
   
problem is sort out thanks
Prerak Patel at 24-Jun-11 12:18pm
   
You are welcome.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

this is dummy program of Insert data into database using store procedure
 
store procedure defination
--------------------------------------------
create procedure sp_Test
(
    @Id int, @Name varchar(50)
)
Insert into table1(Id, FullName) values(@Id,@Name)
--------------------------------------------
 

C# code for call store procedure and insert data in database.(perform it a button click event)
--------------------------------------
try
  {
     sqlConnection = new SqlConnection(dbConnectionString);
     SqlCommand command = new SqlCommand("sp_Test", sqlConnection);
     command.CommandType = CommandType.StoredProcedure;
     command.Parameters.Add("@Id", SqlDbType.VarChar).Value = txtId.Text;
     command.Parameters.Add("@Name", SqlDbType.DateTime).Value = txtName.Text;
     sqlConnection.Open();
     return command.ExecuteNonQuery();
     sqlConnection.Close();
  }
catch (SqlException ex)
  {
     Console.WriteLine("SQL Error" + ex.Message.ToString());
     return 0;
  }
-------------------------------------
 
@Id and @Name is database field parameter value if your table has more field just serially add like
command.Parameters.Add("@Id", SqlDbType.VarChar).Value = txtId.Text;
command.Parameters.Add("@Name", SqlDbType.DateTime).Value = txtName.Text;
.
.
.
.
 
thanks
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 175
1 Zoltán Zörgő 160
2 Peter Leow 100
3 CPallini 70
4 Ramza360 51
0 Sergey Alexandrovich Kryukov 9,568
1 OriginalGriff 6,901
2 Peter Leow 4,737
3 Zoltán Zörgő 4,404
4 CHill60 2,932


Advertise | Privacy | Mobile
Web03 | 2.8.150129.1 | Last Updated 24 Jun 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100