Getting parameters from stored proc

closed account (Gy7oizwU)
Hey Guys

Its the first time i am hooking up my application to a database. I basically want to execute one of the stored procs and use the parameters returned from the proc. (Proc is just a simple select). I am able to connect to the DB and execute the proc but i don't know how to use the parameters thereafter. Can anyone help? I want to use what was selected in the proc in the IF statement of my code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
SqlConnection^ cn = gcnew SqlConnection();
cn->ConnectionString = "user id =sa;"+"password=sa;"+"Trusted_Connection=yes;"+"database=Vet;";
cn->Open();
SqlCommand^ checkUsers = gcnew SqlCommand("sp_CheckUser", cn);
checkUsers->CommandType = CommandType::StoredProcedure;
checkUsers->Parameters->Add(gcnew SqlParameter("@Username", txtbxUsername->Text->ToString()));
checkUsers->Parameters->Add(gcnew SqlParameter("@Password", txtbxPassword->Text->ToString()));

SqlParameter^ RetVal = checkUsers->Parameters->Add("RetVal", SqlDbType::Int);
RetVal->Direction = ParameterDirection::ReturnValue;
checkUsers->ExecuteNonQuery();

if(RetVal->Value->ToString()->Equals("0"))
{
	MessageBox::Show("SP Success");
}
else
{
	MessageBox::Show("Unable to connect user. Please enter a valid username and password " + RetVal->Value->ToString(), "Error Connecting", MessageBoxButtons::RetryCancel, MessageBoxIcon::Exclamation);
}


Thanks
Last edited on
closed account (Gy7oizwU)
Anyone??
closed account (Gy7oizwU)
I was able to solve the issue. The stored proc runs and returns the data. i Can display some of the parameters on my client that i have dev'd except for the image. I am storing an image in the DB as varbinary(max). im not sure how to use that parameter in my c++ code and set the picture box to display that image which the proc returns? Any ideas?
Did you read the link? That explains how to map SQL types to C types.
Topic archived. No new replies allowed.