Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

Im using a ODBC Connection to call a SP (Sybase Stored Proc), It takes 41 parameters, But only needs 10 of the params to execute.

Works fine in SQL but when i use it in my code im not sure how to supply die blank/NULL Values?

Should it be left out or should i use Quotes ("")?

Here is my code:
C#
OdbcConnection cn;
OdbcCommand cmd;

OdbcDataReader dr;
string connetionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString;

    //Change the connection string to use your SQL Server.
    cn = new OdbcConnection(connetionString);

    //Use ODBC call syntax.
    cmd = new OdbcCommand("{call p_MemberAdd_p ("WHAT DO I DO WITH THE EMPTY ARGUMENTS HERE?")}", cn);

    cn.Open();

    dr = cmd.ExecuteReader();

    //List each product.
    while (dr.Read())
        Label1.Text = dr.GetString(1);
        //Label2.Text = dr.GetString(0);

    //Clean up.
    dr.Close();
    cn.Close();
Posted
Updated 19-Mar-12 3:07am
v3
Comments
V. 19-Mar-12 9:07am    
Added Code tags.

Try submitting DBNull.Value
 
Share this answer
 
Comments
man_in_marak 19-Mar-12 9:15am    
Tried this? Same error cmd = new OdbcCommand("{call p_MemberAdd_p (" + DBNull.Value + ")}", cn);
V. 19-Mar-12 9:19am    
I think you need to pass it as a parameter, not inline.
Inline is always dangerous btw. (look up : SQL injection)
In this case DBNull.Value will be serialized as a string and this is not what you want to do.
This is my code:

cmd = new OdbcCommand("{call p_MemberAdd_p (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}", cn);

SQL
CIS = cmd.Parameters.Add("@CIS", OdbcType.VarChar);
                CIS.Value = DBNull.Value;
                OrgId = cmd.Parameters.Add("@OrgId", OdbcType.VarChar, 20);
                OrgId.Value = "CBS";
                ProductId = cmd.Parameters.Add("@ProductId", OdbcType.VarChar, 20);
                ProductId.Value = "AGR";
                MPAcc = cmd.Parameters.Add("@MPAcc", OdbcType.VarChar, 20);
                MPAcc.Value = DBNull.Value;


With all the other params ofcourse

THANKS!!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900