1

I am developing a C# Windows Form Application.

Now i am trying to select value from Listbox and load corresponding value in List view using the stored procedure.

enter image description here

And this is my Stored Procedure: enter image description here

Can any one help please?

Thanks

1
  • If you are this early in development, seriously consider doing this application using WPF instead. It is incredibly better suited to this sort of thing. Commented May 14, 2014 at 10:59

2 Answers 2

1

you have to write an event on selection changed of listbox.then you can get the value of selected value.

  private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ListBox l = sender as ListBox;
        var selectedvalue = l.SelectedItem.ToString();
    }

then you have to pass the orderid to your SP and SP will return the data of that order id and bind that data to ListView.

Sign up to request clarification or add additional context in comments.

Comments

1

Okay so if I interpret your question correctly you are asking for How to call a stored procedure using C#?

This is rather easy to do first you need to initialize an SqlConnection and then you need to issue an SqlCommand - Put that together and you can make calls to a SQL database.

Here is an example for how to make a simple storedprocedure call.

SqlConnection sqlConnection1 = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;

cmd.CommandText = "StoredProcedureName";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = sqlConnection1;

sqlConnection1.Open();

reader = cmd.ExecuteReader();
// Data is accessible through the DataReader object here.

sqlConnection1.Close();

You can read more about it here. How to execute a stored procedure (MSDN)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.