|
hello
I am trying to get the return parameter from database stored procedure (very simple basic test):
create procedure TQMSpGetConcattenatedString @string1 varchar(50),@string2 varchar(50),@string3 varchar(50) output
as
set nocount on
select @string3 = @string1 + @string2
works fine when execute in query analyser. Then try to execute from C# code as follows:
private static string test2()
{
IDbCommand cmd = Program.db.GetCommand ();
cmd.Connection = Program.db.Connection;
cmd.CommandText = "TQMSpGetConcattenatedString";
cmd.CommandType = CommandType.StoredProcedure ;
IDataParameter p1 = Program.db.getDataParameter ();
p1.ParameterName = "@string1";
p1.Direction = ParameterDirection.Input ;
p1.DbType = DbType.String ;
p1.Value = "Monkey";
cmd.Parameters.Add (p1);
IDataParameter p2 = Program.db.getDataParameter ();
p2.ParameterName = "@string2";
p2.Direction = ParameterDirection.Input ;
p2.DbType = DbType.String ;
p2.Value = "Tail";
cmd.Parameters.Add (p2);
IDataParameter p3 = Program.db.getDataParameter ();
p3.ParameterName = "@string3";
p3.Direction = ParameterDirection.Output;
p3.DbType = DbType.String ;
p3.Value = "-";
cmd.Parameters.Add (p3);
cmd.ExecuteNonQuery ();
return p3.Value.ToString();
}
the return string only has 1 character in it. When i use SqlParameter it works good.
Does anybody have a suggestion for me?
|
|
|
|
|
jVersteegen wrote: cmd.ExecuteNonQuery ();
Don't use this. You're executing a query, so use something like ExecuteDataReader() instead. Also, you need to close your connection and command. I suggest that you wrap them up in using blocks.
|
|
|
|
|
Thanks for the suggestion!
I'm not executing a query but a stored procedure.
your suggestion does not change the result.
by the way: what 's the advantage of a using block?
|
|
|
|
|
ExecuteNonQuery is used for update/insert type queries (or stored procs) which do not return data.
The advantage of a using block is that it automatically closes/disposes for you.
you do not get the value of the output parameters until your connection is closed. A starnge thing, but there you are, thats how it works.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Like i say before: when i use SqlDataParameter and not IDataParameter it works fine.
But i want to be able to connect to SqlServer OR Oracle database, so i try IDataParameter.
So it has to with the parameter, not the connection. When i do not set the size for a SqlParameter, the result is also the first character only. However i cannot set the size for IDataParameter.
|
|
|
|
|
You don't need to assign a value to your output parameter. I suspect that it may be setting the size of the parameter because you only assign a single character to the input here.
|
|
|
|
|
tried that: an null value resluts in an error (invalid size property),
a very long string or empty string or gives the same result (only one char).
|
|
|
|
|
What character do you get back? Is it the one you'd expect?
|
|
|
|
|
It is the "M" from "Monkey", but i want "MonketTail".
|
|
|
|
|
found it!
I incidently selected IDataParameter interface, which should have been IDbDataParameter.
IDbDataParameter parameters have a size property.
Thanks for the trouble taken to try to help!
bye.
|
|
|
|
|
Hi all,
I have a problem with DateTimePicker and BindingSource.
The BindingSource DataSource is a DataTable of 3 Columns (ID, Name, and Date).
The "ID" Field is Primary key that of cource doesn't allow nulls.
Both "ID" and "Name" fields are bound to TextBoxes, and "Date" Field is bound to a DateTimePicker control.
Now when I'm trying to add a new record, I got an exception of:
"Column 'ID' does not allow nulls."
although it has a value.
when I don't bind "Date" field, problem doesn't occur
Can you help meeee??
|
|
|
|
|
|
Before actually adding a the new record, you should clear the datetimepicker's databinding, using the method datetimepicker1.DataBindings.Clear() in C#. After that binding the datetimepicker1 to the same data source it's bound before.
|
|
|
|
|
Control.Invoke((MethodInvoker)delegate()
{
});
This is a syntax of a code which i have copied but i didn't understand use of "MethodInvoker" here.
can any body explain me.
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
You cant pass an anonymous delegate into a method expecting a Delegate type. You need to cast it to a compatible delegate type.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 alpha 4a out now (29 May 2008) ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
SO WHAT'S THE USE OF DELEGATE KEYWORD HERE
“You will never be a leader unless you first learn to follow and be led.”
–Tiorio
"Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
|
|
|
|
|
Mogaambo wrote: SO WHAT'S THE USE OF DELEGATE KEYWORD HERE
TO CREATE AN ANONYMOUS DELEGATE!
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 alpha 4a out now (29 May 2008) ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
I'm getting a headache from all this shouting!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
.Invoke(...) takes a type of Delegate. The "delegate(...) {...}" construct is typed as "anonymous-delegate" which cannot be directly assigned to type Delegate. So you cast it to MethodInvoker which is declared as "delegate void MethodInvoker()". This is allowed because "delegate {}" has the same signature.
MethodInvoker, btw is the same as ThreadStart, but without the connotation of it involving threading. Someone decided to put it in the Forms namespace, which is quite annoying.
|
|
|
|
|
I want to restrict user to select received date greater then todays date using RegularExpressionValidator for this i want regular expression.
|
|
|
|
|
You cant do that easily with Regex. I am sure there are other validators that will do what you need.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 alpha 4a out now (29 May 2008) ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Hi
I use proc for reporting
create proc Cpost<br />
@nopersoneli int<br />
as<br />
select p.Fname ,p.lname ,p.NoPersoneli,po.[name] from personal p<br />
join postPersonal pp<br />
on p.NoPersoneli=pp.CPersonal<br />
join post po<br />
on po.code=pp.CPost<br />
where p.NoPersoneli=@nopersoneli<br />
But I don’t understand How I write code?
I made postdataset.xsd and I fill by result of proc.and then I made postcrystalReport.rpt ,I have one form include of CrystalReportViewer1 that ReportSource=postCrystalReport
Please help me about writing code
Thanks a lot
|
|
|
|
|
im trying to use a control to handle both html and rtf formats, in web pages, does anyone know if there are any free controls to do the convertions for me.
i have searched the internet but cant find any, or if C# can do the convertions.
Thank you very much
|
|
|
|
|
Consider that you have two class, which has excatly the same structure. I mean both of them have the same datamembers. For example,
class Foo
{
string myName;
}
class Bar
{
string myName;
}
In such a case, is it possible to serialise foo in to a file and deserialise it as bar ?? I tried the normal way, but it gave me a typecast exception.
Sudarsan Srinivasan
http://codelog.blogial.com
|
|
|
|
|