By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,756 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

StoredProcedures

P: 14
Hi..
Can anyone help in this..
I have created a stored procedure for inserting values in SQLserver2000, coming to frontend i have forms in asp.net with VB.net lang.
I need to call the stored procedure here.I have created connection string and command object.Now how to execute the stored procedure from the button click event??The values are entered through front end and it should store them in database using the procedure.
Can anyone please reply me on these
Apr 19 '07 #1
Share this Question
Share on Google+
3 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Hi..
Can anyone help in this..
I have created a stored procedure for inserting values in SQLserver2000, coming to frontend i have forms in asp.net with VB.net lang.
I need to call the stored procedure here.I have created connection string and command object.Now how to execute the stored procedure from the button click event??The values are entered through front end and it should store them in database using the procedure.
Can anyone please reply me on these
Hi there!

Try doing something like:
Expand|Select|Wrap|Line Numbers
  1. Public Sub InsertCustomer()
  2.     Dim connection As SqlConnection = _
  3.         New SqlConnection(connectionString)
  4.     connection.Open()
  5.     Try
  6.         Dim command As SqlCommand = _
  7.             New SqlCommand("InsertCustomer", connection)
  8.         command.CommandType = CommandType.StoredProcedure
  9.  
  10.         command.Parameters.Add("@CustomerID", "PAULK")
  11.         command.Parameters.Add("@CompanyName", "Pauly's Bar")
  12.         command.Parameters.Add("@ContactName", "Paul Kimmel")
  13.         command.Parameters.Add("@ContactTitle", "The Fat Man")
  14.         command.Parameters.Add("@Address", "31025 La Jolla")
  15.         command.Parameters.Add("@City", "Inglewood")
  16.         command.Parameters.Add("@Region", "CA")
  17.         command.Parameters.Add("@Country", "USA")
  18.         command.Parameters.Add("@PostalCode", "90425")
  19.         command.Parameters.Add("@Phone", "(415) 555-1234")
  20.         command.Parameters.Add("@Fax", "(415) 555-1235")
  21.  
  22.         Console.WriteLine("Rows inserted: " + _
  23.                           command.ExecuteNonQuery().ToString)
  24.  
  25.         Catch ex As Exception
  26.             Console.WriteLine(ex.Message)
  27.             Throw
  28.         Finally
  29.             connection.Close()
  30.         End Try
  31. End Sub
  32.  
The example posted here was taken from this website, check it out if you would like more information.

-Frinny
Apr 19 '07 #2

P: 14
Hi!!

Thanks for the reply.
The code which you have sent me is in c#, but anyways i tried the same in VB.net.
I get the error saying server doesnot exist by highlighting the "Conn.Open()"
I am not able to resolve this problem.
Could you help me??
Apr 20 '07 #3

Frinavale
Expert Mod 5K+
P: 9,731
Hi!!

Thanks for the reply.
The code which you have sent me is in c#, but anyways i tried the same in VB.net.
I get the error saying server doesnot exist by highlighting the "Conn.Open()"
I am not able to resolve this problem.
Could you help me??
Could you copy the exact error that you're getting and post it here.
It'd be helpful if I saw more detail on the error.

-Frinny

(PS. the code supplied is written in VB.NET)
Apr 20 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.