Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > load combo from stored procedure
 

load combo from stored procedure

I've to load list of states in a combobox from sql stored procedure how to this?

somebody help me pls
raveendar  Monday, August 24, 2009 9:33 AM
				DataTable objTbl=null;

				try
				{		
					string sConnectString =  "PROVIDER=SQLOLEDB;" +
						" DATA SOURCE = " + <Your Database Server> + ";" +
						" INITIAL CATALOG = " + <Database Name> + ";" +
						" USER ID= " + <Database User> + ";" +
						" PASSWORD = " + <Database Password> + ";"; 

					OleDbConnection objCon = new OleDbConnection();
					objCon.ConnectionString= sConnectString;
					OleDbCommand objCmd = new OleDbCommand();
					objCmd.Connection = objCon;
					objCmd.CommandType= CommandType.StoredProcedure;
					objCmd.CommandText = <Your ProcedureName>;
					OleDbParameter objParam;
				
					objParam = objCmd.Parameters.Add("RETURN_VALUE",OleDbType.Integer);
					objParam.Direction=ParameterDirection.ReturnValue;			
					
					objCmd.CommandTimeout=0;
					objCon.Open();
					DataSet objDs = new DataSet();
					OleDbDataAdapter objAdap = new OleDbDataAdapter(objCmd);
					objAdap.Fill(objDs,"DATA");
					objTbl = objDs.Tables["DATA"];
					objCon.Close();
combobox.DataSource = objTbl; } catch(Exception ea) { throw ea; }

Please mark the post as answer if it is helpfull to you because it boosts the members to answer more and more.
_SuDhiR_  Monday, August 24, 2009 9:56 AM
				DataTable objTbl=null;

				try
				{		
					string sConnectString =  "PROVIDER=SQLOLEDB;" +
						" DATA SOURCE = " + <Your Database Server> + ";" +
						" INITIAL CATALOG = " + <Database Name> + ";" +
						" USER ID= " + <Database User> + ";" +
						" PASSWORD = " + <Database Password> + ";"; 

					OleDbConnection objCon = new OleDbConnection();
					objCon.ConnectionString= sConnectString;
					OleDbCommand objCmd = new OleDbCommand();
					objCmd.Connection = objCon;
					objCmd.CommandType= CommandType.StoredProcedure;
					objCmd.CommandText = <Your ProcedureName>;
					OleDbParameter objParam;
				
					objParam = objCmd.Parameters.Add("RETURN_VALUE",OleDbType.Integer);
					objParam.Direction=ParameterDirection.ReturnValue;			
					
					objCmd.CommandTimeout=0;
					objCon.Open();
					DataSet objDs = new DataSet();
					OleDbDataAdapter objAdap = new OleDbDataAdapter(objCmd);
					objAdap.Fill(objDs,"DATA");
					objTbl = objDs.Tables["DATA"];
					objCon.Close();
combobox.DataSource = objTbl; } catch(Exception ea) { throw ea; }

Please mark the post as answer if it is helpfull to you because it boosts the members to answer more and more.
_SuDhiR_  Monday, August 24, 2009 9:56 AM
Hi sudhir,
It worked and helpful... thanks a lot sorry I couldn't respond immediately.



raveendar  Monday, August 31, 2009 6:17 AM

You can use google to search for other answers

Custom Search

More Threads

• Help with Tree control
• Auto Incrementing DataGridView Column Increments When Highlighted and Doesn't Update Properly
• Bound DataGridView problem
• How do I use a PropertyGrid in a DataGridViewColumn?
• Datagrid
• User control size increase automatically
• Record Locking and Transactions in Strongly Typed Datasets
• Tip:DataGridView with Combobox rendering performance
• Binding Source Question
• DataGridViewRow.DataBoundItem throws IndexOutOfRangeException