|
|
$Exception {"Column 'Lab_SNo' does not belong to table LabBill."} System.Exception {System.ArgumentException}
What’s wrong in this code? While clicking the button the above exception is raised. Any help me to this problem.
public partial class Lab_frmLabBilling : System.Web.UI.Page
{
DataSet dsBill = new DataSet();
DataTable dtBill = new DataTable("LabBill");
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
InitializeDS();
}
}
catch (Exception ex)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "HMS", ex.Message, false);
}
}
private void InitializeDS()
{
try
{
DataColumn dCol1 = new DataColumn("Lab_SNo",typeof(int));
DataColumn dCol2 = new DataColumn("pk_lab_bill_id",typeof(int));
DataColumn dCol3 = new DataColumn("GroupId",typeof(int));
DataColumn dCol4 = new DataColumn("TestId",typeof(int));
DataColumn dCol5 = new DataColumn("Lab_Test", typeof(string));
DataColumn dCol6 = new DataColumn("Lab_Test_Cost", typeof(float));
dtBill.Columns.Add(dCol1);
dtBill.Columns.Add(dCol2);
dtBill.Columns.Add(dCol3);
dtBill.Columns.Add(dCol4);
dtBill.Columns.Add(dCol5);
dtBill.Columns.Add(dCol6);
dsBill.Tables.Add(dtBill);
}
catch (Exception ex)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "HMS", ex.Message, false);
}
}
protected void btnGInsert_Click(object sender, EventArgs e)
{
try
{
if (txtGroupName.Text == string.Empty)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "HMS", "Please Enter Group Name", false);
return;
}
int iCount;
iCount = dtBill.Columns.Count;
iCount = dtBill.Rows.Count;
iCount++;
DataRow drBill;
drBill = dtBill.NewRow();
drBill["Lab_SNo"] = iCount;
drBill["pk_lab_bill_id"] = iCount;
drBill["GroupId"] = int.Parse(Session["LabGroupId"].ToString());
drBill["TestId"] = 0;
drBill["Lab_Test"] = txtGroupName.Text;
drBill["Lab_Test_Cost"] = float.Parse(Session["TestCost"].ToString());
dtBill.Rows.Add(drBill);
dsBill.AcceptChanges();
grdLabBill.DataSource = dsBill;
grdLabBill.DataBind();
txtGroupName.Text = "";
Session["GroupId"] = 0;
}
catch (Exception ex)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "HMS", ex.Message, false);
}
}
}
Thanks in Advance!
Murali.M
Have A Nice Day!
Murali.M
Blog
modified 2-Mar-12 3:14am.
|
|
|
|
|
Did you debug? It might help if you indicate the faulty line.
(PS: edit your post to highlight the line instead of replying to me. )
[EDIT]Please also put your code between code tags. (select code and press the code button)[/EDIT]
V.
|
|
|
|
|
I think the problem resides where you check the !Page.IsPostBack. When you press a button that runs on the server, the page will go into the Page_Load first and then in the event handler of the button. The state is NOT saved between postbacks so this means that the datatables do not exist yet.
You could or recreate the table on each postback or save the information in a session object and take it out. Like this:
if(!Page.IsPostBack){
}
else{
}
You might want to read up on the Asp.Net Page Life Cycle (see google). That will clarify things.
hope this helps.
V.
|
|
|
|
|
Hi,
When you are calling the page for first time, the DataTable schema are getting initialized.
When you click on button, you are skipping the datatable initialization by putting it into
condition called !Page.IsPostBack. Better you keep the initialized table object in session and during post back access it from session object.
|
|
|
|
|
Well, to start with. If you need datatable in as a member variable then on each postback it will be recreated(no state saved).
So you will be needing a session or cache object to store the table's state.
Have datatable created first time and then push the table in a session/cache object.
on further postbacks first get the value from session/cache and then you are good to go. (do it in form_load as the other events will be fired after that)
|
|
|
|
|
How can the program know the application has ended in comman line console started by System.ServiceProcess.Process.Start("cmd.exe")?
The c# code is as follows:
using System.ServiceProcess;
Process proc = new Process();
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.StandardInput.WriteLine("application.exe");
I appreciate your help.
Sheng
|
|
|
|
|
It can't. It's an indpendent process that doesn't get any information about how or who launched it.
The only way I know of, and probably going to be the easiest, is to write the launched application to take a command line parameter that is passed to it by the launching app.
Whoops. Just went back and reread the question. Since CMD was the app you launched, it doesn't return until the user types EXIT in the CMD window.
If you want to launch application.exe, you can just launch that instead. If you need results from it, you can redirect the StandardIn and StandardOut streams to handlers in your code so you can interact with it.
|
|
|
|
|
Dave:
Thanks! Your answer at least saves me time to make further futile effort.
Could you please elaborate your suggested solution because I am unfamiliar with it? I appreciate your help.
Sheng
|
|
|
|
|
What?? The solution is to run the application.exe instead of launching cmd.exe.
|
|
|
|
|
Do you mean something like this?
if ( Interactive )
{
pr.WaitForExit() ;
}
else
{
while ( !pr.HasExited )
{
this.DoPutOutput ( pr.StandardOutput.ReadLine() ) ;
}
this.DoPutOutput ( pr.StandardOutput.ReadToEnd() ) ;
}
result = pr.ExitCode ;
|
|
|
|
|
pr.WaitForExit() is waiting for cmd.exe to end, not waiting for the application.exe which is run from command line (cmd.exe). application.exe is started from cmd.exe, but runs in a seperate process.
Sheng
|
|
|
|
|
If you start cmd with the arguments /C application.exe , then the cmd process itself will run your app then exit, so you can wait on your proc (cmd) to terminate.
Open a command prompt and enter cmd /? to see other options.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
|
Why don't you do
proc.StartInfo.FileName = "application.exe";
...
proc.Start();
proc.WaitForExit();
int hResult = proc.ExitCode;
|
|
|
|
|
application.exe is a command-line application. It can run only in command line.
"
proc.StartInfo.FileName = "application.exe"
proc.Start()
"
will not start the program.
Sheng
|
|
|
|
|
You should be shelling application.exe, not cmd.exe, unless there's a good reason to do that (I can't think of one).
You can either use WaitForExit, if you want to wait synchronously for a short process, or you can use the Exited event to be notified when a longer process finishes. You need to set EnableRaisingEvents[^] to do it that way (but you probably already have that if you're listening for stdout).
|
|
|
|
|
I tested Peter-in-2780's answer. It works.
Sheng
|
|
|
|
|
Why are you running cmd.exe just to run application.exe. Since your code didn't start the application.exe process, you can't know when it terminates unless you enumerate running processes on the system. The best approach is to skip cmd.exe altogether, and simply run application.exe instead, and make all of the appropriate property settings in the Process object to determine when application.exe actually terminates.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
The problem is that application.exe is a command-line program. It is unable to run directly by Process.StartInfo.FileName = "application.exe". It has to have command line first and then start to run from command line. Peter-in-2780's answer works. Thanks!
Sheng
|
|
|
|
|
Hi all,
Repository[^] pattern with Unit of Work[^] and Dependency Injection, seem to be a universaly accepted solution for ASP.NET + EF applications. There are still some minor questions that I would like to ask here.
Consider the following method from a generic IRepository interface:
public IQueryable<T> Get<T>() where T : class
{
return Set<T>();
}
I wonder, is it a good practice in reveling IQueryable interface to the callers. This means that the calling method can add filters/paggin/sorting, but at the same time the repository itself becomes not unit testable (you cant rely anymore on what the repository will actually return). The caller can even add a non-translatable predicate that will break at runtime. So, is it a good practice in hiding IQueryable interface from the caller, and defining IEnumerable interface instead?
Also, I wonder how do you perform integration tests on repositories? Do you use SQL CE4 , full SQL Server , or just Fake objects on DbContext ?
Appreciate your response,
With regards
modified 1-Mar-12 17:45pm.
|
|
|
|
|
I have no idea, but...
Did you forget to encode your < and > ? He's fixed it.
modified 1-Mar-12 19:34pm.
|
|
|
|
|
I have a program that uses WIA to take and transfer images off of my Nikon D40x. Now I want to add the ability to check battery status on the camera. But have not found a way to do it or if it is even possible. Does anyone have any advise on this?
|
|
|
|
|
Not through WIA it's not.
You'd have to get the Nikon SDK to talk to the camera. I believe you can get that from here[^].
|
|
|
|
|
There has got to be a way. I know there is cont set in WIA for battery status level. Not sure how to use them. And when I plug the camera into the computer, windows uses WIA to communicate with the camera and shows the battery status on the device window.
Have been doing Google searches for hours without any results. How do you pull the properties of the camera through WIA. Such as ISO, shutter speed, etc?
|
|
|
|