Click here to Skip to main content
16,003,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello!

i have one stored prosedure with two parameters
proc_udatabase (@ string1, @string2) 

how to call from c sharp
string querry = ("proc_urdatabase" + "name" + "24") i want to check weather it exist in database or not

how to do it in c sharp

because
SqlDataReader rdr =StoredProcedureCommand.ExecuteReader(); is not working               
SqlDataReader rdr = command.ExecuteReader(); is working but not executing while after it
Posted
Updated 5-Jul-11 23:35pm
v2

Something like this (notice I didn't include try/catch/finally block):

C#
SqlConnection conn   = new SqlConnection(connectionstring);
SqlCommand    cmd    = new SqlCommand("proc_udatabase", conn);
SqlDataReader reader = null;
Datatable     data   = new  DataTable();

conn.Open();
cmd.Parameters.Add(new SqlParameter("@string1", "name");
cmd.Parameters.Add(new SqlParameter("@string2", "24");
reader = cmd.ExecuteReader();
if (reader != null)
{
    data.Load(reader);
}
conn.Close();
 
Share this answer
 
Comments
kami124 6-Jul-11 6:13am    
sorry to disturb you but still my problem didnt sole
can you check here is my c sharp code

sql_string = ("Data Source=000.000.000.000;Initial Catalog=GCERP_SEC;User Id=sa;Password=kamikami;");
SqlConnection conn = new SqlConnection(sql_string);
SqlCommand command = new SqlCommand(str_querry, conn);

conn.Open();

command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@string1" ,SecurityModule.userName_AD);
command.Parameters.AddWithValue("@string2", SecurityModule.moduleid);
// SqlDataReader rdr =StoredProcedureCommand.ExecuteReader();

SqlDataReader rdr = command.ExecuteReader();

if (rdr.HasRows)
{
StringBuilder sb = new StringBuilder();
string a;
while (rdr.Read())
{
sb.Append(((int)rdr["fnid_int"]).ToString());
sb.Append("\n");
a = sb.ToString();
function_name(a);
sb.Length = 0;
}

}
else
{
MessageBox.Show("not found");
}
rdr.Close();
command.ExecuteNonQuery();
count++;
conn.Close();
conn.Dispose();

}
catch (Exception)
{
MessageBox.Show("Error in database connection");
}
}
Hi,

Before executing the command

add this

command.CommandType=CommandType.StoredProcedure
 
Share this answer
 
Comments
kami124 6-Jul-11 6:20am    
i didn't understand
becouse its still not working
my code is there please check it

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