public DataSet ExecuteQuery(string sCommand, string sTableName, ArrayList colParams, CommandType Type) { DataSet oRetVal = new DataSet(); SqlConnection oConn = _GetConnection(false); if (_oException == null) { if (sTableName == null) { sTableName = "Table"; } SqlCommand oCommand = new SqlCommand(); oCommand.CommandText = sCommand; oCommand.Connection = oConn; if (colParams != null) { SqlParameter[] aParams = new SqlParameter[colParams.Count]; colParams.CopyTo(aParams); oCommand.Parameters.Clear(); oCommand.Parameters.AddRange(aParams); } oCommand.CommandType = Type; _oAdapter = new SqlDataAdapter(); _oAdapter.SelectCommand = oCommand; SqlCommandBuilder oBuilder = new SqlCommandBuilder(_oAdapter); try { _oAdapter.Fill(oRetVal, sTableName); } catch (SqlException e) { _oException = e; } finally { if (oConn.State == ConnectionState.Open) { oConn.Close(); } } if (_oException == null) { oCommand.Parameters.Clear(); } } return oRetVal; }Notice that at the bottom I clear the parameters collection. I did this because once a SqlParameter instance is assigned to a command object, it cannot be used again.
SqlParameter pKey = new SqlParameter("RowId", iRowId); ArrayList colParams = new ArrayList(); colParams.Add(pKey); DataSet dsCust = DataProcs.ExecuteQuery("wit_GetCustomer", colParams); DataSet dsInv = DataProcs.ExecuteQuery("wit_GetCustInvoices", colParams);By clearing out the paramaters collection at the end of ExecuteQuery I can reuse the SqlParameters instance. Otherwise, youi
>>CREATE PROCEDURE wit_GetPickListData >> @ItemType VARCHAR(20) >> >>AS >>BEGIN >> >> SELECT ItemKey, ItemType, Caption, ItemDesc >> FROM wit_PickLists >> WHERE ItemType = @ItemType >> ORDER BY Caption >> >>END >>>>
>>// Bind the data set to the listbox >>lstItems.DataSource = dsItems.Tables[0]; >>lstItems.DisplayMember = "Caption"; >> >>lstItems.SelectedIndex = -1; >> >>// Bind the caption >>txtCaption.DataBindings.Add("Text", dsItems.Tables[0], "Caption"); >>>>
>>public void UpdateDataSet(DataSet oDS, string sTableName) >>{ >> if (sTableName == null) >> { >> sTableName = oDS.Tables[0].TableName; >> } >> >> DataTable oTable = oDS.Tables[sTableName]; >> >> foreach (DataRow oRow in oTable.Rows) >> { >> oRow.EndEdit(); >> } >> >> try >> { >> _oAdapter.Update(oDS, sTableName); >> } >> catch (SqlException e) >> { >> throw e; >> } >>} >> >>>>