Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public DataTable GamesForPool(string PoolGame)
        {
            DataTable dtGames = new DataTable();
            try
            { 
                dbCommand = new SqlCommand("PoolGames'" + PoolGame + "'", dbConnection);
                dbAdapter = new SqlDataAdapter(dbCommand);
                dbAdapter.Fill(dtGames);

            }
            catch (SqlException sqlEx)
            {

                MessageBox.Show("Exception " + sqlEx.Message);
            }
           

            return dtGames;
        } 
            try
            {
                dgvGamesforAPool.DataSource = bl.GamesForPool(cboPoolName.SelectedValue.ToString());
            }
            catch (SqlException sqlEx)
            {
                MessageBox.Show("Exception " + sqlEx.Message);
            }
Posted
Updated 13-Oct-11 13:42pm
v2
Comments
Bala Selvanayagam 13-Oct-11 18:55pm    
Please post your stored procedure script too
[no name] 13-Oct-11 21:12pm    
Why?
AspDotNetDev 13-Oct-11 19:06pm    
What's your question?
Sergey Alexandrovich Kryukov 13-Oct-11 19:43pm    
Code sandwiched on <pre lang="cs">...</pre> tag; please always do it for proper formatting.
--SA

Your "question" is not very clear but I do see possible problems

dbCommand = new SqlCommand("PoolGames'" + PoolGame + "'", dbConnection);


Assuming from this that you are attempting to call a stored procedure you must tell the SqlCommand object that is your intention. By default it will assume command text.

dbCommand.CommandType = CommandType.StoredProcedure;


Also, the name you are passing to the constructor will be generated as this "PoolGames'PoolGame'" when I believe you want is this "PoolGamesPoolGame". Notice no single quote.
 
Share this answer
 
I believe you are trying to execute the stored procedure called "PoolGames" with a string parameter of the selected value of the combo box ?

Its worth checking whether you are connecting to the right database where the stored procedure exisits.

The second point is to make sure the stored procedure is named exactly as "PoolGames" (not case sensitive though...) in your database which accepts a single varchar parameter.If the names are different then you will get an error message obviously.


I just did a test and was able to run a similar stored procedure without explicitly setting the command type & it worked...
 
Share this answer
 
v4
what is the exception you got please mention it ????//
 
Share this answer
 
Comments
I.explore.code 14-Oct-11 6:42am    
please post questions on questions as a comment not as a solution...
According to what I can see, your last try..catch block isn't in a valid scope (not method, nor property, nor constructor, nor inline delegate...).
 
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