Showing posts with label field. Show all posts
Showing posts with label field. Show all posts

Saturday, March 31, 2012

Submitting value from a hidden form field

I have a form inserting into an access database, 1 of the fields is hidden and required.
When I click submit the insert fails, if I change the visible value to "true" the insert succeeds.
I know this is probably really simple but I can't figure it out.If you set a controls visibility to false then it doesn't appear in the rendered HTML, therefore your hidden field won't be there at all (check the HTML source). In order to make a control still contain a value but be readonly try using the enabled property and set it to fale instead eg

<asp:TextBox id="myTextBox" enabled="false" runat="server"/>

That way the value is retained but it can't be changed.

Other option is to use a 'traditional' <input type="hidden"> field.
Thanks but the value has to be editable. The hidden field is actually receiving a date that is selected from a calendar on the page using this:


void Selection_Change(Object sender, EventArgs e)
{
countDate.Text = calendar.SelectedDate.ToShortDateString();
}

Where countDate is the hidden field.

If there is an easier way to do this please let me know.
As was explained,

you could use:

<input type="hidden"runat="server" ID="countDate"
Then just the code would be:


countDate.Value = calendar.SelectedDate.ToShortDateString();

Thanks, that worked.

I now have another problem, when changing the date on the calendar it appears to be trying to submit the form, causing error messages as some other fields are also required.

Wednesday, March 28, 2012

substitute data from database into web form

Hello.

Newbie here, I have a field in a database called status with the values "I" or "A". I need to display "Inactive" or "Active" in a gridview or formview web page. How do I substitute these values.

Thanks in advance.

Is this data being displayed in a datalist / datagrid? You can either create a temp table in your sql or modify your code. If you post your code I can show you how, otherwise you can do something like this in your sql:

create table #temp(
activeInactiveField1 char(5)
, activeInactiveField2 char(10)
-- , your other fields here
)

Insert into #Temp(
-- all fields from your existing sql
from all your existing tables

update #temp
set activeInactiveField2 = 'Active'
where activeInactiveField1 = 'A'

update #temp
setActiveInactiveField2 = 'Inactive'
where activeInactiveField1 = 'I'

select * from #Temp
drop table #Temp

Then you can databind the field in your webform to activeInactiveField2


Hello, Thank you for the quick response. Below is my code. As stated I am a newbie and the filed I am working with is status. Thanks a lot.

<%@.PageLanguage="VB"AutoEventWireup="false"CodeFile="Default2.aspx.vb"Inherits="Default2" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataSourceID="SqlDataSource1"

Style="z-index: 100; left: 0px; position: absolute; top: 0px">

<Columns>

<asp:BoundFieldDataField="Citation"HeaderText="Citation"SortExpression="Citation"/>

<asp:BoundFieldDataField="Type"HeaderText="Type"SortExpression="Type"/>

<asp:BoundFieldDataField="Status"HeaderText="Status"SortExpression="Status"/>

<asp:BoundFieldDataField="Last Name"HeaderText="Last Name"SortExpression="Last Name"/>

<asp:BoundFieldDataField="First Name"HeaderText="First Name"SortExpression="First Name"/>

<asp:BoundFieldDataField="Middle"HeaderText="Middle"SortExpression="Middle"/>

<asp:BoundFieldDataField="DOB"HeaderText="DOB"SortExpression="DOB"/>

<asp:BoundFieldDataField="Violation Date"HeaderText="Violation Date"SortExpression="Violation Date"/>

<asp:BoundFieldDataField="Charge"HeaderText="Charge"SortExpression="Charge"/>

<asp:BoundFieldDataField="Description"HeaderText="Description"SortExpression="Description"/>

<asp:BoundFieldDataField="Disposition"HeaderText="Disposition"SortExpression="Disposition"/>

<asp:BoundFieldDataField="Cost"HeaderText="Cost"SortExpression="Cost"/>

<asp:BoundFieldDataField="Paid"HeaderText="Paid"SortExpression="Paid"/>

<asp:BoundFieldDataField="Balance"HeaderText="Balance"SortExpression="Balance"/>

</Columns>

</asp:GridView>

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:MUNI_COURTConnectionString4 %>"

ProviderName="<%$ ConnectionStrings:MUNI_COURTConnectionString4.ProviderName %>"

SelectCommand="SELECT * FROM [MUNI_COURT_REC]"></asp:SqlDataSource>

</div>

</form>

</body>

</html>


You can handle this in RowDataBound event of the gridview. To add this event to your gridview, when in design view of Visual Studio, click on gridview once to get the properties window. From that, go to the events window (identified by a small "lightning" icon) and look for RowDataBound event. Double click on this event and an event hadler will created in your code file. Just copy and paste this code there.

protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e) {if (e.Row.RowType == DataControlRowType.DataRow) {if(e.Row.Cells[7].Text =="A") { e.Row.Cells[7].Text ="Active"; }else { e.Row.Cells[7].Text ="Inactive"; } } }

Or you can change your select statement - something like select case status when 'i' then 'inactive' else 'active' end as status from blah blah blah...

By the way, it's never good practice to do a select *.


Hi, try this inline IIF statement to evaulate the status field and display conditional text. You will have to first convert your GridView to a template so you have control over the HTML controls.

<asp:LabelID="LabelStatus"runat="server"Text='<%# IIF(CONVERT.ToString(Eval("Status"))="A","Active", "Inactive") %>'></asp:Label>


Thanks I got that suggestion to work in a gridview and formview. Big Smile

What if I had another field called type that I had to change

"H" to "Harbor"

"C" to "Civil"

"T" to "Traffic"

"L" to "Local"


You can use the same solutions that are marked as answer to extend the functionality. Like in mine, you can access the columns by their index (0 based). So whatever the index of your "Type" column, access it in RowDataBound event, check the text of the cell, and change it accordigly.


Sorry bullpit,

when I run your suggestion I get the following error message

Compiler Error Message:BC30205: End of statement expected.

I believe your suggestion would work best.

I forgot to uncheck the answer message button


Paste your code here. Please use the InsertCode option in the text editor.


Partial Class Default2 Inherits System.Web.UI.Page Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBoundprotected void gridView1_RowDataBound(object sender, GridViewRowEventArgs e) {if (e.Row.RowType == DataControlRowType.DataRow) {if(e.Row.Cells[7].Text =="A") { e.Row.Cells[7].Text ="Active"; } Else { e.Row.Cells[7].Text ="Inactive"; } } } End SubEnd Class

Thanks


learn_asp_fast:

Partial Class Default2 Inherits System.Web.UI.Page Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBoundprotected void gridView1_RowDataBound(object sender, GridViewRowEventArgs e) {if (e.Row.RowType == DataControlRowType.DataRow) {if(e.Row.Cells[7].Text =="A") { e.Row.Cells[7].Text ="Active"; } Else { e.Row.Cells[7].Text ="Inactive"; } } } End SubEnd Class

The piece of code I posted was an event handler for RowDataBound event. An event handler is a method (function) by itself. What you did was that you attached an event handler the way I mentioned (by double clicking the RowDataBound event in designer) but also copied and pasted the event handler that I posted into the event handler that the designer generated. So now you have a function defined in another function, which is not right. Morover, you are using VB and the code I pasted was C#. Change the above code to this:

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBoundIf e.Row.RowType = DataControlRowType.DataRowThen If e.Row.Cells(7).Text ="A"Then e.Row.Cells(7).Text ="Active"Else e.Row.Cells(7).Text ="Inactive"End If End If End Sub

Bullpit,

Thank you very much for your time. I did realize I pasted the code into another function, but neith er way worked for me. I should be able to get this sample to work in other ways for me.

This a very helpful board.


Also, change the column index (7 in the code I posted) to the column index where you want to change the text. That might be the problem. For example, in your gridview, the "STATUS" colum index maybe 4 instead of 7.


Bullpit,

If you do not mind hopw do I get that to work in a Formview?

Thanks in advance

Substituting for a value returned from a db

Just started in both C# and .net so please go gentle
I have a bit field in a db and need to substitue for the 0 or 1 value
Basically if it's 0 I need to output 15 min and if it's 1 I need to out put 30 min
I have no idea where to begin and the tutorials were just confusing me more.
Thanks in advance for your help.

if(myVal == 0)
myVal = 15;

Zath
Alright I guess this is my fault for not explaning better what I was looking for

I think I am on the right track here as digging around I found some more out but again I hit a road block
I should store the result of the query in a datatable and then parse through the table row by row
How do I get the total value of the number of returned rows.
Basically a php convert here so this is what I am looking to do in php
While ($row = mysql_fetch_array($result)) {
// code stuffs to do here each and every time like
if ($row[4] == 0) {
$row[4] = 15 min;
} else {
$row[4] = 30 min;
}
Simply for display purposes though

How to approach this depends on the context in which you will be using this. Are you going to use a list control like a DataGrid, DataList or a Repeater? What does your Sql Statement look like, and how do you store the returned result?
If you are using a DataReader, e.g. an SqlDataReader, and the Bit field is located at index '0' in the Sql, the code could look like this (not tested):
string minutes = null;
con.Open();
rdr = cmd.ExecuteReader();
while(rdr.Read())
{
if((bool)rdr["MyBitField"])
minutes = "30 min";
else
minutes = "15 min";
}
rdr.Close();
con.Close();

Okay then how would I then make the minutes variable appear where the normal rdr["MyBitField"] would have?


Read my message. I cannot answer this until you explain where and how you want to display these values.

Sorry about that I thought I was understanding something that I obviously wasn't sorryEmbarrassed [:$]
This is what I have so far and I would like to display in a datagrid

string break_type =null;

SqlConnection mySqlConnection =newSqlConnection("server = '**********'; database = '*******'; uid = '*********'; pwd = '*********'");

SqlDataAdapter myCommand =newSqlDataAdapter("SELECT break_time, type FROM schedule", mySqlConnection);

DataTable break_table =newDataTable();

DataRow break_row;

break_table.Columns.Add(newDataColumn("IntegerValue",typeof(Int32)));

break_table.Columns.Add(newDataColumn("StringValue",typeof(string)));

break_table.Columns.Add(newDataColumn("BooleanValue",typeof(bool)));

for (int i = 1; i <= 4; i++) {

break_row = break_table.NewRow();

break_row[0] = break_row[0];

break_row[1] = break_row[1];

if (break_row[2] == 0) {

break_type ="15 min";

}else {

break_type = ToString() +"30 min";

}

break_table.Rows.Add(break_row);

}

ScheduleGrid.DataSource =newDataView(break_table);

ScheduleGrid.DataBind();


Try this:
void BindGrid()
{
string conn = "server=someserver;database=somedb;uid=sa;pwd=secret";
string sql = "SELECT break_time, type FROM schedule";

SqlConnection con = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;

SqlDataReader rdr;

con.Open();

rdr = cmd.ExecuteReader();

ScheduleGrid.DataSource = rdr;
ScheduleGrid.DataBind();

rdr.Close();
con.Close();

}
To check the Bit value and display the correct Min value, use the ItemDataBound Event of the DataGrid:
void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType item = e.Item.ItemType;

switch(item)
{
case ListItemType.AlternatingItem :
case ListItemType.Item :

// Use a TemplateColumn in your DataGrid to hold the Minute value.
// Add a Label Control (ID = lblMin) to yr TemplateColumn
Label lbl = (Label)e.Item.FindControl("lblMin");
string min = "15 minutes";
if((bool)(DataBinder.Eval(e.Item, "DataItem.break_time")))
min = "30 minutes";
lbl.Text = min;
break;
}
}


Thanks for the help

I feel more confused now then before as I thought I was close but looking at your solution it doesn't even resemble what I had and since I truly don't understand what your code is doing or how it is doing it I will keep on looking.

I am not trying to discount your help at all just rather unless I can understand something I don't like it to be in the applications I am working on and I can't understand you above code.


To help further, I have actually made a working demo solution for you. You need to change the SQL details. I would recommend you get yourself a book on how to develop Asp.Net Applications. "Asp.Net Unleashed by Stephen Walther (SAMS)" is excellent, and will get you up standard fast.
Code follows:
<%@. Page Language="C#" Trace="False" %>
<%@. Import NameSpace="System" %>
<%@. Import NameSpace="System.Web" %>
<%@. Import NameSpace="System.Web.UI" %>
<%@. Import NameSpace="System.Web.UI.WebControls" %>
<%@. Import NameSpace="System.Data" %>
<%@. Import NameSpace="System.Data.SqlClient" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script runat="server">

void Page_Load(object s, EventArgs e)
{
if(!IsPostBack)
{
BindGrid();
}
}


void BindGrid()
{
string conn = "server=(local);trusted_connection=true;database=breakdemo";
string sql = "SELECT break_time, break_type FROM breaktbl";

SqlConnection con = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;
SqlDataReader rdr;

con.Open();

rdr = cmd.ExecuteReader();

ScheduleGrid.DataSource = rdr;
ScheduleGrid.DataBind();

rdr.Close();
con.Close();

}

//To check the Bit value and display the correct Min value, use the ItemDataBound Event of the DataGrid:

void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType item = e.Item.ItemType;

switch(item)
{
case ListItemType.AlternatingItem :
case ListItemType.Item :

// Use a TemplateColumn in your DataGrid to hold the Minute value.
// Add a Label Control (ID = lblMin) to yr TemplateColumn
Label lbl = (Label)e.Item.FindControl("lblMin");

string min = "15 minutes";

if((bool)(DataBinder.Eval(e.Item, "DataItem.break_time")))
min = "30 minutes";

lbl.Text = min;

break;
}
}


</script>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form runat="server" ID="form1">
<asp:DataGrid Id="ScheduleGrid"
RunAt="server"
HeaderStyle-BackColor="#808080"
HeaderStyle-ForeColor="#FFFFFF"
ItemStyle-BackColor="#FFFFFF"
AlternatingItemStyle-BackColor="#E1E3E8"
PagerStyle-Visible="true"
OnItemDataBound="DataGrid1_ItemDataBound"
AutoGenerateColumns="False">
<columns>
<asp:boundcolumn datafield="Break_Type" headertext="Reason for Break" readonly="true"></asp:boundcolumn>
<asp:templatecolumn headertext="Break time">
<itemstyle horizontalalign="Center"></itemstyle>
<itemtemplate>
<asp:label id="lblMin" runat="server"></asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:DataGrid>
</form>
</body>
</html>


Thank you very much - it was actually the output portion that I was struggling with.

could you elaborate a bit more on this statement?
case ListItemType.AlternatingItem :

I changed the code according (sql statements)
and generated a Specified Cast not valid error on this line
if((bool)(DataBinder.Eval(e.Item, "DataItem.break_time")))

Thank you so much for your help through this - I don't know why I am just struggling mightely here


Every other line (DataGridItem) displaying a record is an "AlternatingItem". Practical, as you can e.g. use different bg colors on Item/Alternating ListItemTypes to make your grid more readable.
As for the "Cast not valid" error, I'm puzzled. If "break_time" is an SQL Bit datatype as you say, this should work. I have reproduced your scenario, so I know that my code works.
Thank you very much
I needed to bool check to go from type, not break_time didn't even double check that sorry
Once again thank you very much for your help and seeing this through for me. I fele you went above and beyond for me.
I am sure I will be back with other issues and if I am helped out half as mucha gain in the future I have no fear.

alright so I have taken your code and added things that I need to add however it seems like an awful long wat to go for what I need and maybe it is just me doing things the long way or this is just going to be the norm but can someone take a look and let me know if I am on the right track as far as how to do this

<%@.PageLanguage="C#"Trace="False"Debug="true"%>
<%@.ImportNameSpace="System" %>
<%@.ImportNameSpace="System.Web" %>
<%@.ImportNameSpace="System.Web.UI" %>
<%@.ImportNameSpace="System.Web.UI.WebControls" %>
<%@.ImportNameSpace="System.Data" %>
<%@.ImportNameSpace="System.Data.SqlClient" %>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">
<scriptrunat="server">
void Page_Load(object s,EventArgs e)
{
// To be able to use template like variables in the page
Page.DataBind();
if(!IsPostBack)
{
BindGrid();
}
}
// To store the value in a template like variable
string PageTitle{
get {
return"Break Schedule";
}
}
void BindGrid()
{
string conn ="server=******;database=raintranet;uid=sa;pwd=*****";
string sql ="SELECT s.break_time, s.type, b.day_id as break_day, u.first_name, u.last_name FROM schedule as s, break_data as b LEFT JOIN users as u ON b.users_id = u.users_id WHERE b.schedule_id = s.schedule_id ORDER BY break_day, s.break_time";
SqlConnection con =newSqlConnection(conn);
SqlCommand cmd =newSqlCommand(sql, con);
cmd.CommandType =CommandType.Text;
SqlDataReader rdr;
con.Open();
rdr = cmd.ExecuteReader();
ScheduleGrid.DataSource = rdr;
ScheduleGrid.DataBind();
rdr.Close();
con.Close();
}
//To check the Bit value and display the correct Min value, use the ItemDataBound Event of the DataGrid:
void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType item = e.Item.ItemType;
switch(item)
{
caseListItemType.AlternatingItem :
caseListItemType.Item :
// Use a TemplateColumn in your DataGrid to hold the Minute value.
// Add a Label Control (ID = lblMin) to yr TemplateColumn
Label lbl = (Label)e.Item.FindControl("lblMin");
string min ="15 min";
if ((bool)(DataBinder.Eval(e.Item,"DataItem.type")))
{
min ="30 min";
}
lbl.Text = min;
// Do the same for the day
Label daylbl = (Label)e.Item.FindControl("lblDay");
string day ="Sunday";
string dayVal;
dayVal =DataBinder.Eval(e.Item,"DataItem.break_day").ToString();
if (String.Compare(dayVal,"2") == 0)
{
day ="Monday";
}
elseif (String.Compare(dayVal,"3") == 0)
{
day ="Tuesday";
}
elseif (String.Compare(dayVal,"4") == 0)
{
day ="Wednesday";
}
elseif (String.Compare(dayVal,"5") == 0)
{
day ="Thursday";
}
elseif (String.Compare(dayVal,"6") == 0)
{
day ="Friday";
}
elseif (String.Compare(dayVal,"7") == 0)
{
day ="Saturday";
}
//------ Make the name string valid ------
Label name_lbl = (Label)e.Item.FindControl("lblName");
string Full_name;
Full_name =DataBinder.Eval(e.Item,"DataItem.first_name").ToString();
Full_name = Full_name +" " +DataBinder.Eval(e.Item,"DataItem.last_name").ToString();
name_lbl.Text = Full_name;
daylbl.Text = day;
break;
}
}

</script>
<html>
<head>
<title><%# PageTitle %></title>
</head>
<body>
<formrunat="server"ID="form1">
<asp:DataGridId="ScheduleGrid"
RunAt="server"
HeaderStyle-BackColor="#808080"
HeaderStyle-ForeColor="#FFFFFF"
ItemStyle-BackColor="#FFFFFF"
AlternatingItemStyle-BackColor="#E1E3E8"
PagerStyle-Visible="true"
OnItemDataBound="DataGrid1_ItemDataBound"
AutoGenerateColumns="False"
cellpadding="2">
<columns>
<asp:boundcolumndatafield="break_time"headertext="Time"readonly="true"></asp:boundcolumn>
<asp:templatecolumnheadertext="Type">
<itemstylehorizontalalign="Center"></itemstyle>
<itemtemplate>
<asp:labelid="lblMin"runat="server"></asp:label>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumnheadertext="Day">
<itemstylehorizontalalign="Center"></itemstyle>
<itemtemplate>
<asp:labelid="lblDay"runat="server"></asp:label>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumnheadertext="Day">
<itemstylehorizontalalign="Center"></itemstyle>
<itemtemplate>
<asp:labelid="lblName"runat="server"></asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:DataGrid>
</form>
</body>
</html>
That will output a table with the following data
Break | Type | Day | Who
6:00 15 min Sat Rick
6:15 30 min Sun Tara
So on and so forth


First off - the code looks good ( though all those {} and ; always look funny to me Smile [:)]
I would just like to add that there are other ( maybe easier ) ways todo this. As is the case with programming - there are many ways toperform the same action.
I would do something like this for the full name field :
<itemtemplate>
<asp:labelid="lblName"runat="server" text='<%#DataBinder.Eval(Container.DataItem, "First_Name") + " " +DataBinder.Eval(Container.DataItem, "Last_Name")%>' />
</itemtemplate>
For the Type
<asp:templatecolumnheadertext="Type">
<itemstylehorizontalalign="Center"></itemstyle>
<itemtemplate>
<asp:labelid="lblMin"runat="server" text='<%# IIF(DataBinder.Eval(Container.DataItem, "type"),"30 min","15 min") %> ' />
</itemtemplate>
</asp:templatecolumn>
then for the day I would either use a helper function like this :
<asp:templatecolumnheadertext="Day">
<itemstylehorizontalalign="Center"></itemstyle>
<itemtemplate>
<asp:labelid="lblDay"runat="server"text='<%# GetDay(DataBinder.Eval(Container.DataItem, "break_day"))%>' />
</itemtemplate>

then add a function like
Function GetDay(MyDay) as string
Select Case MyDay
case 1
return "Sun"
Case 2
return "Mon"
.....
End Function
Sorry not C# - i think it's switch
Then you don't need the OnItemDataBound event

If one of the columns is the actual date (instead of a number representing a day) then you could do something like
<asp:templatecolumnheadertext="Day">
<itemstylehorizontalalign="Center"></itemstyle>
<itemtemplate>
<asp:labelid="lblDay"runat="server"text='<%#DataBinder.Eval(Container.DataItem, "ActualDateField")).DayOfWeek %>' />
</itemtemplate>
HTH
PS - just realized that C# doesn't have IIF - maybe there is an equivalent - maybe "?"
cond-expr ? expr1 : expr2
<asp:labelid="lblMin"runat="server" text='<%# (DataBinder.Eval(Container.DataItem, "type")==1) ? "30 min":"15 min"; %> ' />

Saturday, March 24, 2012

Sum result in Label field

I summed a column of numbers and would like to put them in a Label field to display the result. I understand the conversion for number to string, I don't understand how to that value, that has been summed, to do it.

thanks
grady

int x = 7;
int y = 7;
int z = x + y;

LabelID.Text = z.ToString();

Is that what you're looking for?

HTH,
Ryan


Actually I have summed a column called TFsum and I was trying to display that and it say it was undeclared.

Here is the SQL:
SELECT SUM(filesfailed) AS TFsum
FROM accmonreport
WHERE oa='ddlOA'
HAVING SUM(filesfailed)=0

ddlOA is a dropdown list in the first view on the page. I'm just to get the variable TFsum to do some calculations.

thanks
grady


Could you post the relevent code?

Ryan


All I'm trying now is get the TFsum value into the lblcompliant label.

thanks
grady

Imports System.Data
Imports System.Data.OleDB
Imports System.Data.OleDb.OleDbDataReader

Partial Class reports_508report
Inherits System.Web.UI.Page

Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

If (Page.IsValid) Then

Dim ddlOA As String = ddloalist.SelectedValue

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\accmon\database\accmon.mdb" & ";"
Dim MySQL As String = "SELECT SUM(filesfailed)AS TFsum FROM accmonreport WHERE oa='ddlOA' HAVING filesfailed=0"
Dim MyConn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(MySQL, MyConn)
MyConn.Open()
cmd.ExecuteReader()
MyConn.Close()

lblCompliant.Text = " "

OAReport.SetActiveView(Result)
End If

End Sub

End Class


You need to make a couple of changes.

If (Page.IsValid) Then

Dim ddlOA As String = ddloalist.SelectedValue

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\accmon\database\accmon.mdb" & ";"
Dim MySQL As String = "SELECT SUM(filesfailed)AS TFsum FROM accmonreport WHERE oa='" & ddlOA & "' HAVING filesfailed=0"
Dim reader As OleDbDataReader
Dim MyConn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(MySQL, MyConn)
MyConn.Open()
reader =cmd.ExecuteReader()

While reader.Read()
lblCompliant.Text = reader("TFsum")
End While

reader.Close()
MyConn.Close()

OAReport.SetActiveView(Result)
End If

HTH,
Ryan


Thanks, I really appreciate your time and knowledge. If you don't mind, I have one more question. In Coldfusion there is a function that gives me a recordcount after every query. How do you implement something like that in .Net?

thanks
grady