Instead of the braces, I'm sorry my example was unclear, use a period...
("@howmany", SqlDbType.Int,4) //In this example, 4 is the length
("@howmany", SqlDbType.Int) //You leave off length, it's one of the many
overloads.
Either way, you can add a period 'value and the value at the end
("@howmany", SqlDbType.Int,4).Value = txtMealdsec.Text;
To execute it, you'll need to fire myCommand.ExecuteReader or
myCommand.ExecuteScalar, da.Fill(myTable) //where da has cmd defined as it's
SELECT Command. If you aren't familiar with executing queries in ADO.NEt,
you may want to check out these articles, they'll definitely help you...
http://www.betav.com/msdn_magazine.htm
Also, make sure that the command command's type is set to StoredProcedure..
As far as spped...here's the deal. Stored Procs are preferably to dynamic
sql for many reasons...performance is one of them. However, that doesn't
mean that a Stored Proc can't be slow. Make sure your table has a Primary
Key (Always!) and/or Clustered Index if this is SQL Server. If you have a
really large table, you'll more than likely want to have an index on the
restriction field(s). If performance is really important, run it through
the Index Tuning Wizard and see what it tells you. Performance is a complex
issue and in general things are trade off as opposed to black or white. So
I can't really do the whole subject justice here. The short answer though
is that Procs with Param passed in should perform better than the same query
passed in through Dynamic Sql.
HTh,
Bill
Parag said:
Hi William,
Can i just ask what i am supposed to write in the
[YourTypeHere] box. I tried inserted the datatype of
meal_desc and cost but it doesn't like this..
.Add("@Meal_desc", SqlDBType[Char]).Value =
txtMealdesc.Text
.Add("@Cost", SqlDbType[currency]).Value =
txtCost.Text
Also how does the SPROC know that it needs to run when
the button is clicked?
I want the sproc to be passed the parameters, run and
then place the results in a datagrid.
Is it implied that the sproc should run by the fact that
we are passing the parameters to it in the code u have
given me?
Many thanx
-----Original Message-----
Assuming that you have everythig working other than the parameters issue....
With cmd.Parameters
.Clear
.Add("@Mead_desc", SqlDBType[YourTypeHere]).Value = SomeValue
.Add("@Cost", SqlDbType[YourTypeHere]).Value = SomeMoneyValue
End With
There are multiple overloads for Parameters that I'd encourage you to
investigate. You can use .Add("@Mead_desc", SomeValue) without passing the
type and a few others...it's up to you. Not sure about your second
question, but I do know that Enterprise Manager for example, isn't really
great at showing things refreshed. I'd try a screen refresh and see if they
appear then.
HTH,
Bill
Hi,
I wanted to know how i can call stored procedure and pass
it 2 parameters when a button is clicked.
my code for the stored procedure is:
INSERT INTO Available_Meals(Meal_desc, Cost) VALUES
(@Meal_desc, @Cost);
SELECT Meal_desc, Cost FROM Available_Meals WHERE
(Meal_desc = @Meal_desc)
any help would be excellent.
Also does anyone know why the sprocs i create do not
appear straight away the the server explorer? I have to
close VS.net down and then reopen the project to make
them visible.
.