I have to populate a listbox with details of a particular customer.
For example, you may want to view a Customer with the current products for that Customer. List Box should display the current prouct name registered by that customer.
Here goes my try,
Form1.cs:
private void ProductsRegistered(string UserName, string productID)
{
UserData.ProductsRegistered proreg = userdata.GetRegisteredProducts(UserName, productID);
listBox1.DataSource = proreg;
listBox1.DisplayMember = proreg.ProductName;
}
userdata.cs:
public struct ProductsRegistered
{
public string ProductID;
public string ProductName;
}
public ProductsRegistered GetRegisteredProducts(string UserName, string ProductID)
{
ArrayList arlist = new ArrayList();
ProductsRegistered proreg = new ProductsRegistered();
DataTable dtUsers = new DataTable();
string strSQL = "SELECT DISTINCT a.UserID,a.ProductID,b.[Name] FROM myacc_userregisteredProducts a inner join InstallationProduct b on a.ProductID=b.[ID]inner join myacc_users c ON a.UserID=c.[ID]WHERE c.UserName ='" + UserName + "'";
SqlConnection sqlConn = new SqlConnection("server=Intra; database=vc; uid=sa; pwd=ore");
sqlConn.Open();
SqlCommand cmd = new SqlCommand(strSQL, sqlConn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
proreg.ProductID = dr[0].ToString();
proreg.ProductName = dr[1].ToString();
}
dr.Close();
sqlConn.Close();
//listBox1.DataSource = proreg;
//listBox1.DisplayMember = "productName";
}
Help is appreciated!Thanks in Advance!