Solarion
Honorary Master
- Joined
- Nov 14, 2012
- Messages
- 28,051
- Reaction score
- 17,804
Am I doing this right? It works just fine but I'm wondering what you guys do when you need to return a list of items from the DB, perhaps an easier/simpler way.
This is the function.
And here is where I call it.
This is the function.
Code:
public List<String> CreateDetails(DateTime TransactionDate, string submissionid)
{
string sql = "select distinct CustomerNumber from tblCustDetails where transaction_date = '" + TransactionDate + "' and submission_id = '" + submissionid + "'";
String myConnString = ConfigurationManager.ConnectionStrings["Connection"].ToString();
SqlConnection myConnection = new SqlConnection(myConnString);
SqlCommand myCommand = new SqlCommand();
myCommand.CommandType = CommandType.Text;
myCommand.Connection = myConnection;
myCommand.CommandText = myCommand.CommandText = sql;
try
{
myConnection.Open();
List<String> CustomerNumberInfoColl = new List<String>();
SqlDataReader sqlDataReader = myCommand.ExecuteReader();
if (sqlDataReader.HasRows)
{
while (sqlDataReader.Read())
{
CustomerInfo customerNumber = new CustomerInfo();
CustomerNumberInfoColl.Add(sqlDataReader["CustomerNumber"].ToString());
}
}
return CustomerNumberInfoColl;
}
catch (Exception ex)
{
throw ex;
}
finally
{
myConnection.Close();
}
}
And here is where I call it.
Code:
private void RefreshListBox()
{
CustomerInfo ficCustomerNumber = new CustomerInfo();
List<String> CusList = CreateDetails(Convert.ToDateTime(dtDateTime.Value.Date.ToString("M/d/yyyy")), this.txtID.Text);
if (CusList.Count > 0)
{
foreach (String item in CusList)
{
listBox1.Items.Add(item.ToString());
}
}
}
Last edited:
