Hi Guys,
I am trying to populate two arrays with data from database but without success...can someone shed more light on this....
I dont get any errors but i am not sure whether the arrays are being populated or not
Ok here are my other two question on the bolded parts of the code....
if we have a query like
Select * from employees
then we say
DataSet objDS = new DataSet("employees");
objDA.Fill(objDS, "employees");
but for my query which has more than one table how do i write the DataSet("????")
and the other thing
i want itemtotal to be integer how can i cast to it to integer value??
thanks in advance....
-VJ
I am trying to populate two arrays with data from database but without success...can someone shed more light on this....
I dont get any errors but i am not sure whether the arrays are being populated or not
Code:
<%@ Import Namespace="System"%>
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.Collections"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Import Namespace="System.Drawing"%>
<script language="C#" runat="server">
int i=0;
void Page_Load(Object Sender, EventArgs e) {
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=STJSQL\STJDB;" +
"Database=STJData;" +
"User ID=XXXX;" +
"Password=XXXXXX";
string sql= "SELECT t.Description as InventName, SUM(CASE WHEN m.Active_Ind =1 THEN 1 ELSE 0 END) as itemtotal FROM Inventory_Main m join Inventory_Type t on m.Inventory_Type_ID=t.Inventory_Type_ID GROUP BY m.Inventory_Type_ID, t.Description ORDER BY t.Description ASC ";
SqlCommand objcommand= new SqlCommand(sql,conn);
SqlDataAdapter objDA = new SqlDataAdapter(objcommand);
conn.Open();
[b]DataSet objDS = new DataSet("Inventory_Main");
objDA.Fill(objDS, "Inventory_Main");
[/b]
ArrayList sItems = new ArrayList();
ArrayList iValue = new ArrayList();
foreach(DataRow row in objDS.Tables[0].Rows)
{
ListItem listitem = new ListItem();
ListItem itemvalue = new ListItem();
listitem.Text= row["InventName"].ToString();
[b]itemvalue.Value = row["itemtotal"].ToString();[/b]
sItems.Add(listitem);
iValue.Add(itemvalue);
i++;
}
}
</script>
Ok here are my other two question on the bolded parts of the code....
if we have a query like
Select * from employees
then we say
DataSet objDS = new DataSet("employees");
objDA.Fill(objDS, "employees");
but for my query which has more than one table how do i write the DataSet("????")
and the other thing
i want itemtotal to be integer how can i cast to it to integer value??
thanks in advance....
-VJ