Add SQL row to a ASP label based on a condition - c#

SQL Table:
ID CreatedDate MessageText CreatedBy IsActive ClientText LocationText ProviderText SpecialtyText
1 March 4, 2015 dsdfsdf Test1 False
2 March 4, 2015 dsdfsdf Test2 True
3 March 4, 2015 dsdfsdf Test2 True Test Client location1 Test2 MD
4 March 4, 2015 This is to add Test1 False Test Client location2 Test3 DD
Getting the table:
using (SqlConnection conn = new SqlConnection(gloString))
{
string strSql = #"SELECT * FROM [DB].[dbo].[table2]";
try
{
// create data adapter
SqlDataAdapter da = new SqlDataAdapter(strSql, conn);
// this will query your database and return the result to your datatable
myDataSet = new DataSet();
da.Fill(myDataSet);
}
catch (Exception ce)
{
}
}
I have the following label in my ASP.net page: <asp:Label ID="lblMessage" Font-Size="x-small" runat="server" Text="" ClientIDMode="Static"></asp:Label>
How can I update the label like this:
lblMessage.Text += "<b>ALL MESSAGES:</b> <br />";
foreach (ROW WHERE COLUMN {CLIENTTEXT}, {LOCATIONTEXT}, {PROVIDERTEXT}, AND {SPECIALTYTEXT} IS EMPTY)
{
lblMessage.Text += {CREATEDDATE} + " - " + {MESSAGETEXT} + "<br /><br />";
}
lblMessage.Text += "<hr />";
lblMessage.Text += "<b>SPECIFIC MESSAGES:</b> <br />";
foreach (ROW WHERE COLUMN {CLIENTTEXT}, {LOCATIONTEXT}, {PROVIDERTEXT}, OR {SPECIALTYTEXT} IS NOT EMPTY)
{
lblMessage.Text += {CREATEDDATE} + " - " + {MESSAGETEXT} + "<br /><br />";
}

The way I get it, you want to update your label using the rows that dont contain a "SpecialityText". The problem is you dont know how.
Let's say the DataSet you use in your page is still named myDataSet after you fetch it, the following code should do the trick. Please note I assumed you have some data access namespace imported. DBNull.Value should be replaced with whathever the null representation your helper uses.
string specific = "";
string generic = "";
foreach (DataRow r in myDataSet.tables[0].Rows){
//Add all your conditions here. It seems you want two groups of messages
if (r["SpecialtyText"].ToString == ""){
generic += r["CreatedDate"] + " - " + r["MessageText"] + "<br /><br />";
}
else{
specific += r["CreatedDate"] + " - " + r["MessageText"] + "<br /><br />";
}
}
lblMessage.Text = generic + "<hr /><b>SPECIFIC MESSAGES:</b> <br />" + specific;

I don't see a difference for the 2 for loops you showed.
If it's just one table you should be using a DataTable instead of a DataSet
You can do it like this:
foreach (DataRow row in table.Rows)//table is a DataTable
{
var clientText = row["ClientText"].ToString();
var locationText = row["LocationText"].ToString();
var providerText = row["ProviderText"].ToString();
var specialtyText = row["SpecialtyText"].ToString();
var createdDate = row["CreatedDate"].ToString();
var messageText = row["MessageText"].ToString();
if (string.IsNullOrEmpty(clientText) &&
string.IsNullOrEmpty(locationText) &&
string.IsNullOrEmpty(providerText) &&
string.IsNullOrEmpty(specialtyText))
{
lblMessage.Text += createdDate + " - " + messageText + "<br /><br />";
}
}
then add else block if you need. You can also use linQ
foreach (var clientText in from DataRow row in table.Rows
let clientText = row["ClientText"].ToString()
let locationText = row["LocationText"].ToString()
let providerText = row["ProviderText"].ToString()
let specialtyText = row["SpecialtyText"].ToString()
where string.IsNullOrEmpty(clientText) &&
string.IsNullOrEmpty(locationText) &&
string.IsNullOrEmpty(providerText) &&
string.IsNullOrEmpty(specialtyText)
select clientText)
{
//some code here
}

Related

How to retrieve value from dynamic text box using C#?

I am using tree view in my web application, but I am using dynamic input text box when tree view data bind. The code is:
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
tables = node[0].ChildNodes[0].SelectNodes("col[#text='" + ds.Tables[0].Rows[i]["ModuleName"].ToString() + "']");
TreeNode MyRoot = new TreeNode();
string GUID = Guid.NewGuid().ToString();
MyRoot.Text = " " + ds.Tables[0].Rows[i]["ModuleName"].ToString() + " " + "<input type='text' id='" + GUID + "' />";
MyRoot.Value = ds.Tables[0].Rows[i]["ModuleName"].ToString();
if (RootNode != ds.Tables[0].Rows[i]["ModuleName"].ToString())
{
tv_GetMenu.Nodes.Add(MyRoot);
RootNode = ds.Tables[0].Rows[i]["ModuleName"].ToString();
var rows = from row in ds.Tables[0].AsEnumerable()
where row.Field<string>("ModuleName").Trim() == RootNode
select row;
DataTable dt = new DataTable();
dt = rows.CopyToDataTable();
if (dt != null)
{
if (dt.Rows.Count > 0)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
string GUID1 = Guid.NewGuid().ToString();
TreeNode MyChild = new TreeNode();
if ((dt.Rows[j]["PageName"].ToString().Trim() != "Master Config") && (dt.Rows[j]["PageName"].ToString().Trim() != "Upload") && (dt.Rows[j]["PageName"].ToString().Trim() != "label configuration") && (dt.Rows[j]["PageName"].ToString().Trim() != "Dashboard Report"))
{
MyChild.Text = " " + dt.Rows[j]["PageName"].ToString() + " " + "<input type='text' id='" + GUID1 + "' value='" + dt.Rows[j]["PageName"].ToString() + "'/>";
MyChild.Value = dt.Rows[j]["Address"].ToString();
MyRoot.ChildNodes.Add(MyChild);
}
}
}
}
}
}
The above code is working properly, but when I run the application and enter value in dynamic created text box then I am not getting this text box value for saving at run time. How we can access this value at run time?

Is it possible to match two series of data in a chart from two different datasets in c# winforms

I am working on a application to chart boards inspected and board with defects based on work order number. I realize after looking at the chart and comparing the actual data, that the series do not match up for work order number. I am at a loss on how to match both series to the work order number to get a correct chart.
Here is my code for the data pull Boards_Inspected pulled first
public DataSet Get_Boards_Inspected(string startDate, string endDate, int location)
{
DataSet ds = new DataSet();
NpgsqlConnection conn = DatabaseConnection.getConnectionString();
try
{
conn.Open();
NpgsqlDataAdapter da = new NpgsqlDataAdapter("select new_table.top_or_bottom, new_table.board_wo_number, count(new_table.board_serial_number) from" +
" (select distinct master_board.board_serial_number, board_wo.board_wo_number,board_wo.board_part_number, board_time.top_or_bottom from master_board" +
" inner join board_time on board_time.board_time_id = master_board.id" +
" inner join board_wo on board_wo.board_wo_number = master_board.board_wo_number" +
" where time_in between '" + startDate + "' and '" + endDate + "'" +
" and board_time.location_id = '" + location + "')" +
" as new_table" +
" group by new_table.top_or_bottom, new_table.board_wo_number" +
" order by top_or_bottom;", conn);
ds.Reset();
da.Fill(ds);
da.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("An unexpected error has occured with the application. \n" +
"An email has been sent to the software developer for analysis. \n" +
"this program will now close.", "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
eMessageBody = ex.ToString();
Mail sendMessage = new Mail();
sendMessage.SendSMTP(eMessageBody, eMessageSubject);
Application.Exit();
}
finally
{
conn.Close();
}
return ds;
}
Board with defects
public DataSet Get_Boards_With_Issue(string startDate, string endDate, int location)
{
DataSet ds = new DataSet();
NpgsqlConnection conn = DatabaseConnection.getConnectionString();
try
{
conn.Open();
NpgsqlDataAdapter da = new NpgsqlDataAdapter("select new_table.top_or_bottom, new_table.board_wo_number, count(new_table.defect_id) from" +
" (select distinct defect_id, top_or_bottom, board_wo_number from defect" +
" inner join master_board on defect.defect_id = master_board.id" +
" where defect_time between '" + startDate + "' and '" + endDate + " 23:59:59'" +
" and location_id = '" + location + "')" +
" as new_table" +
" group by new_table.top_or_bottom, new_table.board_wo_number" +
" order by top_or_bottom;", conn);
ds.Reset();
da.Fill(ds);
da.Dispose();
}
catch(Exception ex)
{
MessageBox.Show("An unexpected error has occured with the application. \n" +
"An email has been sent to the software developer for analysis. \n" +
"this program will now close.", "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
eMessageBody = ex.ToString();
Mail sendMessage = new Mail();
sendMessage.SendSMTP(eMessageBody, eMessageSubject);
Application.Exit();
}
finally
{
conn.Close();
}
return ds;
}
Here is my chart series assignment code
private void Boards_Without_Issue_Chart(string starDate, string endDate, int location)
{
try
{
#region Chart Setup
chart1.Series.Clear();
chart1.Series.Add("Boards Inspected");
chart1.Series.Add("Boards Without Issue");
chart1.Series.Add("Boards With Issue");
chart1.Series["Boards Inspected"].Points.Clear();
chart1.Series["Boards Without Issue"].Points.Clear();
chart1.Series["Boards With Issue"].Points.Clear();
chart1.Series["Boards Inspected"]["LabelStyle"] = "Top";
chart1.Series["Boards Without Issue"]["LabelStyle"] = "Top";
chart1.Series["Boards With Issue"]["LabelStyle"] = "Top";
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.Series["Boards Inspected"].ChartType = SeriesChartType.Column;
chart1.Series["Boards Without Issue"].ChartType = SeriesChartType.Column;
chart1.Series["Boards With Issue"].ChartType = SeriesChartType.Column;
chart1.Series["Boards Inspected"]["DrawingStyle"] = "LightToDark";
chart1.Series["Boards Without Issue"]["DrawingStyle"] = "LightToDark";
chart1.Series["Boards With Issue"]["DrawingStyle"] = "LightToDark";
if (chart1.Titles.Contains(t1))
{
t1.Font = new System.Drawing.Font("Microsoft Sans serif", 14, FontStyle.Bold);
t1.Text = titleText + " - Boards Without Issue - (" + startDate + " - " +endDate+ ")";
}
else
{
t1.Name = "tTitle1";
t1.Font = new System.Drawing.Font("Microsoft Sans serif", 14, FontStyle.Bold);
t1.Text = titleText + " - Boards Without Issue - (" + startDate + " - " + endDate + ")";
chart1.Titles.Add(t1);
}
chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Microsoft Sans serif", 14, FontStyle.Bold);
chart1.ChartAreas[0].AxisY.Title = "Amount of Boards";
chart1.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Microsoft Sans serif", 14, FontStyle.Bold);
chart1.ChartAreas[0].AxisX.Title = "Work Order";
chart1.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
chart1.ChartAreas[0].AxisX.LabelStyle.Font = new System.Drawing.Font("Microsoft Sans serif", 12, FontStyle.Regular);
chart1.Series["Boards Inspected"].IsValueShownAsLabel = true;
chart1.Series["Boards With Issue"].IsValueShownAsLabel = true;
#endregion
#region Chart Data Assignment
DataAccess DA = new DataAccess();
DataAccess DA2 = new DataAccess();
DataSet mda = new DataSet();
if ((DA.Get_Boards_Inspected(startDate, endDate, location).Tables[0].Rows.Equals(0)) &&
(DA2.Get_Boards_With_Issue(startDate, endDate, location).Tables[0].Rows.Equals(0)))
lblError.Text = "No information Availiable";
else
{
foreach (DataTable tb in DA.Get_Boards_Inspected(startDate, endDate, location).Tables)
{
foreach (DataRow dr in tb.Rows)
{
object tpn = dr["top_or_bottom"];
var ct = (dr["count"].ToString());
var wo = (dr["board_wo_number"].ToString());
if (tpn == DBNull.Value)
chart1.Series["Boards Inspected"].Points.AddXY(wo, ct);
else
chart1.Series["Boards Inspected"].Points.AddXY(wo + " - " + tpn, ct);
}
}
DA.Get_Boards_Inspected(startDate, endDate, location).Clear();
DA.Get_Boards_Inspected(startDate, endDate, location).Dispose();
foreach (DataTable tb2 in DA2.Get_Boards_With_Issue(startDate, endDate, location).Tables)
{
foreach (DataRow dr2 in tb2.Rows)
{
object tpn2 = dr2["top_or_bottom"];
var ct = (dr2["count"].ToString());
var wo = (dr2["board_wo_number"].ToString());
if (tpn2 == DBNull.Value)
chart1.Series["Boards With Issue"].Points.AddXY(wo, ct);
else
chart1.Series["Boards With Issue"].Points.AddXY(wo + " - " + tpn2, ct);
}
}
DA2.Get_Boards_With_Issue(startDate, endDate, location).Clear();
DA2.Get_Boards_With_Issue(startDate, endDate, location).Dispose();
}
#endregion
}
catch(Exception ex)
{
MessageBox.Show("An unexpected error has occured with the application. \n" +
"An email has been sent to the software developer for analysis. \n" +
"this program will now close.", "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
eMessageBody = ex.ToString();
Mail sendMessage = new Mail();
sendMessage.SendSMTP(eMessageBody, eMessageSubject);
Application.Exit();
MessageBox.Show(ex.ToString());
}
}
EDIT: Here is the code for the chart data
DataAccess DA = new DataAccess();
DataAccess DA2 = new DataAccess();
DataSet mda = new DataSet();
if ((DA.Get_Boards_Inspected(startDate, endDate, location).Tables[0].Rows.Equals(0)) &&
(DA2.Get_Boards_With_Issue(startDate, endDate, location).Tables[0].Rows.Equals(0)))
lblError.Text = "No information Availiable";
else
{
foreach (DataTable tb in DA.Get_Boards_Inspected(startDate, endDate, location).Tables)
{
foreach (DataRow dr in tb.Rows)
{
object tpn = dr["top_or_bottom"];
var ct = (dr["count"].ToString());
var wo = (dr["board_wo_number"].ToString());
if (tpn == DBNull.Value)
chart1.Series["Boards Inspected"].Points.AddXY(wo, ct);
else
chart1.Series["Boards Inspected"].Points.AddXY(wo + " - " + tpn, ct);
}
}
DA.Get_Boards_Inspected(startDate, endDate, location).Clear();
DA.Get_Boards_Inspected(startDate, endDate, location).Dispose();
foreach (DataTable tb2 in DA2.Get_Boards_With_Issue(startDate, endDate, location).Tables)
{
foreach (DataRow dr2 in tb2.Rows)
{
object tpn2 = dr2["top_or_bottom"];
var ct = (dr2["count"].ToString());
var wo = (dr2["board_wo_number"].ToString());
if (tpn2 == DBNull.Value)
chart1.Series["Boards With Issue"].Points.AddXY(wo, ct);
else
chart1.Series["Boards With Issue"].Points.AddXY(wo + " - " + tpn2, ct);
}
}
DA2.Get_Boards_With_Issue(startDate, endDate, location).Clear();
DA2.Get_Boards_With_Issue(startDate, endDate, location).Dispose();
EDIT: Links
Both data sets, trying to line them up in a chart
Recent chart
This is a classic mistake when working with Chart controls.
They seem to do everything automagically right until you get a little closer and hit upon problems.
Here is the rule:
All Values, both X-Values and all Y-Values are internally stored as doubles.
If you feed in numbers all works fine. If you feed in any other data type you are heading for trouble somewhere down the line.
At first all seems to work and the stuff you feed into shows up nicely in the labels.
But when you want to use any advanced ability of the Chart, chances are it won't work..
This can be something as simple as formatting the labels, which works with string formats only. If you want to use a number format you need to feed in numbers!
You are hitting upon the problem of matching up points in different series.
You have fed in the X-Values as strings and so the trouble starts as soon as the data points need matching beyond the order in which you add them.
You could feed them in the precise order but you need to understand what happens..
Lets have a look behind the scenes..: If you use the debugger to look into the x-Values of your series' datapoints, you will be amazed to see that they all are 0! The strings you fed in, have gone into the labels, but the X-Values are all the result of the failed conversion to double, resulting in 0. This means all datapoint have the same X-Value!
You have two options:
Either add them all in synch, all in the same order and the same number of points in all series.
Use numbers for X-Values.
Your workOrder looks like a number; if it is you can use it, if you want to, but it will then spread out the data according to those numbers. Probably not a good idea. Instead you can assign each workorder an index and use this instead.
To create nice labels use the AxisLabel property for each data point!
It is easiest, imo to create a DataPoint first with values and axislabel and maybe tooltips and colors and whatnot and then add it to the points collection.
Now to let this sink in, have a look at this chart:
This is the code to create it:
private void Form1_Load(object sender, EventArgs e)
{
Random R = new Random(1);
List<Tuple<Series, int>> misses = new List<Tuple<Series, int>>();
chart1.Series.Clear();
for (int i = 0; i < 3; i++ )
{
Series s = new Series("S" + (i + 1));
s.ChartType = SeriesChartType.Column;
chart1.Series.Add(s);
}
chart1.ChartAreas[0].AxisX.Interval = 1;
foreach(Series s in chart1.Series)
{
for (int i = 0; i < 30; i+=3)
{
if (R.Next(3) > 0) s.Points.AddXY(i, i+1);
else misses.Add(new Tuple<Series, int>(s, i));
}
}
foreach (Tuple<Series, int> m in misses)
{
if (m.Item1.Name == "S1") m.Item1.Points.AddXY(m.Item2 + "X", m.Item2 + 5);
else m.Item1.Points.AddXY(m.Item2, m.Item2 + 5);
}
for (int i = 0; i < chart1.Series[0].Points.Count - 1; i++)
{
chart1.Series[0].Points[i].AxisLabel = chart1.Series[0].Points[i].XValue + "%";
}
}
Let's have a look at the things that happen:
I first create three series and then fill a few points into them. However I randomly leave a few slots empty.
I store these in a List of Tuples, so I can later add them out of order.
And you can see that they all match up, except for the blue series 'S1'.
Can you see why?
I always use a nice number for the X-Values, but not for the missed points in the blues series, where I have attached an "X" to the number.
Now these points are added too, but all with an X-Value of 0 and so they all sit at position 0.
Note: Note that the above is not code you can use. It is code to study to learn about the data types of Chart values and the consequences of adding strings as X-Values!
I figured it out, I first changed my DataSets into DataTables. I then created a new column in DataTable 1 that will hold the count field in DataTable 2. I then looped through all the row in DataTable 1 and looped through DataTable 2 and put a select condition to match the top_or_bottom and board_wo_fields and pulled the count value for each match out of DataTable 2 and put them in DataTable 1.
DataTable dt1 = DA.Get_Boards_Inspected(startDate, endDate, location);
DataTable dt2 = DA2.Get_Boards_With_Issue(startDate, endDate, location);
DataColumn newCol = new DataColumn("dcount", typeof(System.Object));
newCol.AllowDBNull = true;
dt1.Columns.Add(newCol);
foreach(DataRow r in dt1.Rows)
{
object wo = (r["board_wo_number"]).ToString();
object tp = (r["top_or_bottom"]).ToString();
if (tp == "")
{
foreach (DataRow r1 in dt2.Select("board_wo_number = '" + wo + "'"))
{
if (r1["count"] == DBNull.Value)
r["dcount"] = 0;
else
r["dcount"] = (r1["count"]);
}
}
else
{
foreach (DataRow r1 in dt2.Select("board_wo_number = '" + wo + "' and top_or_bottom = '" + tp + "'"))
{
if (r1["count"] == DBNull.Value)
r["dcount"] = 0;
else
r["dcount"] = (r1["count"]);
}
}
}
foreach (DataRow dr in dt1.Rows)
{
object tpn = (dr["top_or_bottom"]);
object ct = (dr["count"]).ToString();
object wo = (dr["board_wo_number"]).ToString();
object ct2 = (dr["dcount"]).ToString();
if (tpn == DBNull.Value)
{
chart1.Series["Boards Inspected"].Points.AddXY(wo, ct);
chart1.Series["Boards With Issue"].Points.AddXY(wo, ct2);
}
else
{
chart1.Series["Boards Inspected"].Points.AddXY(wo + " - " + tpn, ct);
chart1.Series["Boards With Issue"].Points.AddXY(wo + " - " + tpn, ct2);
}
}

Add lines below rows dynamically

I have written this code to send an email when an change is made in a gridview.
I send an email with changes made in the column in row format. I need to add a line below each row and I am using this code and it doesn't work.
I have used this part to add line below rows sbMsg.AppendFormat("<table rules=" + rows + " style=' font-family:Calibri;background-color:#F1F1F1' width='1000'>");
public string mailFormatting(string Code)
{
List<string> lstSpecificColumns = new List<string>();
DataTable dtCurrentTbl = activeApplication.LoadMailActiveApplications(Code.ToString().Trim());
DataTable dtOldTbl = activeApplication.LoadMailLogManualUpdatesDetails(Code.ToString().Trim());
for (int colIndex = 0; colIndex < dtCurrentTbl.Columns.Count; colIndex++)
{
if (!dtCurrentTbl.Rows[0][colIndex].ToString().Equals(dtOldTbl.Rows[0][colIndex].ToString()))
{
lstSpecificColumns.Add(dtCurrentTbl.Columns[colIndex].ColumnName);
}
}
dtCurrentTbl.Merge(dtOldTbl);
DataTable resultTbl = dtCurrentTbl.AsEnumerable().CopyToDataTable().DefaultView.ToTable(true, lstSpecificColumns.ToArray());
string rows = "\"rows\"";
StringBuilder sbMsg = new StringBuilder();
sbMsg.AppendFormat("<p><font color=gray>Title<font></p>");
sbMsg.AppendFormat("<table rules= + rows + style='font-family:Calibri;background-color:#F1F1F1' width='1000'>");
sbMsg.AppendFormat("<tr> <td colspan='2'> <font color=blue> <u> " + Code.ToString().Trim() + " </u></font><td></tr>");
foreach (DataColumn dc in resultTbl.Columns)
{
sbMsg.AppendFormat("<tr>");
sbMsg.AppendFormat("<td> " + dc.ColumnName.Trim() + " </td>");
sbMsg.AppendFormat("<td> <strike>" + resultTbl.Rows[1][dc].ToString().Trim() + "</strike>" + " " + resultTbl.Rows[0][dc].ToString().Trim() + " </td>");
sbMsg.AppendFormat("</tr>");
}
sbMsg.AppendFormat("</table>");
return sbMsg.ToString();
}
Can anyone help me in this.

Datatype mismatch in criteria expression.in a select query c# Access database

I am building a simple Point of Sale program and working on a "search invoice" button that allows up to 3 search criteria (InvoiceID , ClientName, and ClientID). These are the names of 3 of the columns in the table named "Invoicing".
InvoiceID is the key column of type Int32, ClientName is of type String, ClientID is of type Int32. ClientName and ClientID searches work perfect.
MY PROBLEM: If I include InvoiceID in the select query, I get the following error. And I have spent a few days trying to figure it out.
ERROR: Database Error: Datatype mismatch in criteria expression.
Can you more experienced programmers help me out? thank you!
String connectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data" + #" Source=TESTDB.accdb";
String tableName = "Invoicing";
String query = String.Format("select * from [{0}] where", tableName);
//ADD IN SEARCH CRITERIA
int filled = 0;
if (invoiceBox.Text != "") { query += " InvoiceID='" + invoiceBox.Text+"'"; filled += 1; }
/*if (DateCheckBox.Checked == true)
{
if (filled>=1) { query += " and DateNTime='" + monthCalendar1.SelectionStart.ToString() + "'"; filled += 1; }
else { query += " DateNTime='" + monthCalendar1.SelectionStart.ToString()+ "'"; filled += 1; }
}
* */
if (ClientNameBox.Text != "") //Doesnot work
{
if (filled >= 1) { query += " and Client='" + ClientNameBox.Text + "'"; filled += 1; }
else { query += " Client='" + ClientNameBox.Text + "'"; filled += 1; }
}
if (ClientIDBox.Text != "") //THIS search criteria works!!!!
{
if (filled >= 1) { query += " and ClientID='" + ClientIDBox.Text + "'"; filled += 1; }
else { query += " ClientID='" + ClientIDBox.Text + "'"; filled += 1; }
}
//CHECK IF SEARCH CRITERIA ARE PRESENT
if (filled < 1) { MessageBox.Show("At least One Search criteria above is required"); return; }
DataSet dsInvoicing = new DataSet();
OleDbConnection conn = new OleDbConnection(connectionString);
try
{
//Open Database Connection
conn.Open();
OleDbDataAdapter daInvoicing = new OleDbDataAdapter(query, conn);
//Fill the DataSet
daInvoicing.Fill(dsInvoicing, tableName);
//MessageBox.Show("dsInventory has "+dsInventory.Tables[0].Rows.Count+" search results");
conn.Close();
this.dataGridView1.DataSource = dsInvoicing.Tables[0];
}
catch (OleDbException exp){ MessageBox.Show("Database Error: " + exp.Message.ToString());}
Need more information? I will post up more if I haven't provided enough.
DATABASE INFORMATION or other.
Thank you very much to all programmers.
Looks like the data type of InvoiceID in your database is some numeric kind. While in query you are treating it as string. Try not to wrap InvoiceID value in single quotes.

How to read a checkbox value generated from a label?

Hi, I'm facing this problem getting the value of the checkbox value that I generated from C# code in a label. The output is just as I wanted, but i've tried using the below codes, but the object tells me its value is null. Someone please guide me, I need help.
HtmlInputCheckBox MyCheckBox = new HtmlInputCheckBox();
MyCheckBox = (HtmlInputCheckBox)this.FindControl("Qn" + temp);
bool isChacked = MyCheckBox.Checked;
MyMethod
string table1 = "";
ArrayList listofquestionnonradio = DBManager.GetSurveyQuestionNonRadio();
ArrayList listofallquestion = DBManager.GetAllSurveyQuestions();
int lastcount = Convert.ToInt32(listofquestionnonradio.Count);
table1 = "<br/><table>";
foreach (SurveyQuestions surv in listofallquestion)
{
if (surv.Questionid <= listofquestionnonradio.Count)
{
//get questions without radio
table1 += "<tr><td><b>Q" + temp + ")</b></td><td>" + surv.Question + "</td></tr><tr><td valign=top>Ans:</td><td>";
foreach (string subjname in listofselectsubjectnames)
{
//get name from excludelist
bool result= DBManager.GetExcludedQuestionsByQidAndSubject(surv.Questionid, subjname);
if (result == false)
{
string subvalue = subjname + "_val";
table1 += "<input type=checkbox name=Qn" + counterqn + " value=" + subvalue + " >" + subjname + "<br>";
counterqn++;
}
}
table1 += "<input type=checkbox name=lastqn value=NIL)>All of the above<br/></td></tr>";
table1 += "<tr style=height:10px></tr>";
temp++;
}
else
{
//get questions id if they are disable
bool result= DBManager.GetExcludedQuestionsByQid(surv.Questionid);
if (result == false)
{
//get questions with radio
table1 += "<tr><td><b>Q" + temp + ")<b></td><td>" + surv.Question + "</td></tr><tr><td valign=top>Ans:</td><td>";
table1 += "<input type=radio name=Qn" + counterqn + " value=1>Strongly disagree<br><input type=radio name=Qn" + counterqn + " value=2>Disagree<br><input type=radio name=Qn" + counterqn + " value=3>Agree<br><input type=radio name=Qn" + counterqn + " value=4>Strongly agree<br><input type=radio name=Qn" + counterqn + " value=5>Not applicable<br></td></tr>";
table1 += "<tr style=height:10px></tr>";
}
else
{
temp--;
}
temp++;
}
}
table1 += "</table><br/>";
I think the reason why you cannot access the checkbox controls is because you are not actually using server controls, you are building up your markup yourself. Your WebForm therefore does not have any controls to find.
If you are using ASP.NET WebForms (which is what I'm assuming) then why don't you use the server controls to build your table rather than manually building the HTML? You would then be able to view/modify them in your code-behind.
Take a look at the GridView control for a start to see how you could build up a table/grid-view easier than what you are currently doing.

Categories