472,989 Members | 3,058 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

problem ado.net application

hi. i m mohsin
i m making a gui application using c# at front end and sql server 2005
at backend...... i made a table in sql server 2005 with 4 columns and
in gui i used 4 text boxes and 4labels and three buttons. my full code
is mentioned below....... button1 is for add button2 is for save and
button3 is for delete...
the table is empty..but the lines prefix with ---- are giving
errors............ plz tel me why............ i also used a binding
navigator and bind all the columns correctly.............

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace CITY_HOSPITAL
{

public partial class Form20 : Form
{
DataTable dt;
DataRow dr;
string code;
public Form20()
{
InitializeComponent();

}

private void textBox3_TextChanged(object sender, EventArgs e)
{

}

private void Form20_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'cITY_HOSPITALDataSet.SERVICESMAINTENANCE' table. You can move, or
remove it, as needed.

this.sERVICESMAINTENANCETableAdapter.Fill(this.cIT Y_HOSPITALDataSet.SERVICESMAINTENANCE);
textBox1.Enabled = false;
textBox2.Enabled = false;
textBox3.Enabled = false;
textBox4.Enabled = false;
button2.Enabled = false;
}

private void button1_Click(object sender, EventArgs e)
{
button2.Enabled = true;
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
int ctr, len;
string codeval;
dt = cITY_HOSPITALDataSet.Tables["SERVICESMAINTENANCE"];
----- len = dt.Rows.Count - 1;
---- dr = dt.Rows[len];
code = dr["SERVICEID"].ToString();
codeval = code.Substring(1, 5);
ctr = Convert.ToInt32(codeval);
if ((ctr >= 1) && (ctr < 9))
{
ctr = ctr + 1;
textBox1.Text = "SER00" + ctr;
}
else if ((ctr >= 9) && (ctr < 99))
{
ctr = ctr + 1;
textBox1.Text = "SER0" + ctr;
}
else if (ctr >= 99)
{
ctr = ctr + 1;
textBox1.Text = "SER" + ctr;
}
button1.Enabled = false;
}

private void button2_Click(object sender, EventArgs e)
{
dt = cITY_HOSPITALDataSet.Tables["SERVICESMAINTENANCE"];
dr = dt.NewRow();
dr[0] = textBox1.Text;
dr[1] = textBox2.Text;
dr[2] = textBox3.Text;
dr[3] = textBox3.Text;
dt.Rows.Add(dr);

sERVICESMAINTENANCETableAdapter.Update(cITY_HOSPIT ALDataSet);
textBox2.Text = System.Convert.ToString(dr[0]);
textBox1.Enabled = false;
textBox2.Enabled = false;
textBox3.Enabled = false;
textBox4.Enabled = false;

this.sERVICESMAINTENANCETableAdapter.Fill(this.cIT Y_HOSPITALDataSet.SERVICESMAINTENANCE);
button1.Enabled = true;
button2.Enabled = false;
}

private void button3_Click(object sender, EventArgs e)
{
string code;
code = textBox1.Text;
if (textBox1.Text.Length == 0)
{
MessageBox.Show("PLEASE SELECT A VALID RECORD");
}
else
{
dr =
cITY_HOSPITALDataSet.Tables["SERVICESMAINTENANCE"].Rows.Find(code);
dr.Delete();

sERVICESMAINTENANCETableAdapter.Update(cITY_HOSPIT ALDataSet);
}

}

}

}

Aug 19 '08 #1
7 922
but the lines prefix with ---- are giving errors

What errors? (please copy the exact error message)

The code you posted gives an idea, but we can't use that "as is" to
investigate anything. But if you give us the error message we might be
able to help.

Can I guess "NullReferenceException", "Object reference not set to an
instance of an object."?

In which case either the table isn't called "SERVICESMAINTENANCE"
inside the DataSet (just enumerate the .Tables to see what *is*
there), or you haven't loaded it correctly. Try using the table as:
dt = cITY_HOSPITALDataSet.SERVICE*SMAINTENANCE;

Or simply check that your DataSet is not completely empty.

Marc
Aug 19 '08 #2
On Aug 19, 12:59*pm, Marc Gravell <marc.grav...@gmail.comwrote:
but the lines prefix with ---- are giving errors

What errors? (please copy the exact error message)

The code you posted gives an idea, but we can't use that "as is" to
investigate anything. But if you give us the error message we might be
able to help.

Can I guess "NullReferenceException", "Object reference not set to an
instance of an object."?

In which case either the table isn't called "SERVICESMAINTENANCE"
inside the DataSet (just enumerate the .Tables to see what *is*
there), or you haven't loaded it correctly. Try using the table as:
dt = cITY_HOSPITALDataSet.SERVICE*SMAINTENANCE;

Or simply check that your DataSet is not completely empty.

Marc
ok buddy.......
the error is "there is no row at position -1" however if i change to 0
or +1 the error is there is no row at position 0 or +1 respectively....
Aug 19 '08 #3
On Aug 19, 6:14*pm, "mo/-/sin" <Ri.moh...@gmail.comwrote:
On Aug 19, 12:59*pm, Marc Gravell <marc.grav...@gmail.comwrote:
but the lines prefix with ---- are giving errors
What errors? (please copy the exact error message)
The code you posted gives an idea, but we can't use that "as is" to
investigate anything. But if you give us the error message we might be
able to help.
Can I guess "NullReferenceException", "Object reference not set to an
instance of an object."?
In which case either the table isn't called "SERVICESMAINTENANCE"
inside the DataSet (just enumerate the .Tables to see what *is*
there), or you haven't loaded it correctly. Try using the table as:
dt = cITY_HOSPITALDataSet.SERVICE*SMAINTENANCE;
Or simply check that your DataSet is not completely empty.
Marc

ok buddy.......
the error is"INDEXOUTOFRANGEEXCEPTION" below this it is written that
"there is no row at position -1" however if i change to 0
or +1 the error is there is no row at position 0 or +1 respectively...
Aug 19 '08 #4
On Aug 19, 6:23*pm, "mo/-/sin" <Ri.moh...@gmail.comwrote:
On Aug 19, 6:14*pm, "mo/-/sin" <Ri.moh...@gmail.comwrote:
On Aug 19, 12:59*pm, Marc Gravell <marc.grav...@gmail.comwrote:
but the lines prefix with ---- are giving errors
What errors? (please copy the exact error message)
The code you posted gives an idea, but we can't use that "as is" to
investigate anything. But if you give us the error message we might be
able to help.
Can I guess "NullReferenceException", "Object reference not set to an
instance of an object."?
In which case either the table isn't called "SERVICESMAINTENANCE"
inside the DataSet (just enumerate the .Tables to see what *is*
there), or you haven't loaded it correctly. Try using the table as:
dt = cITY_HOSPITALDataSet.SERVICE*SMAINTENANCE;
Or simply check that your DataSet is not completely empty.
Marc

ok buddy.......
the error is"INDEXOUTOFRANGEEXCEPTION" below this it is written that
"there is no row at position -1" however if i change to 0
or +1 the error is there is no row at position 0 or +1 respectively...
as per your suggestion i insert two rows directly into that table
using sql server 2005... but now the error is in the line " ctr =
Convert.ToInt32(codeval); " and the error is formatexception was
unhandled and below that it is written that INPUT STRING WAS NOT IN A
CORRECT FORMAT'.............
Aug 19 '08 #5
OK, so the original error was that there weren't any rows and you
weren't checking for this...

The second error; what is a typical "codeval" value when you debug it?

Marc
Aug 19 '08 #6
On Aug 19, 7:40*pm, Marc Gravell <marc.grav...@gmail.comwrote:
OK, so the original error was that there weren't any rows and you
weren't checking for this...

The second error; what is a typical "codeval" value when you debug it?

Marc
as i told u there are three buttons in my application and when i debug
that application i m not able see the application instead of that i
see this error.............
Aug 19 '08 #7
as i told u there are three buttons in my application and when i debug
that application *i m not able see the application instead of that i
see this error.............
There are lots of ways of getting a value if the debugger isn't happy
- write the value to the console, the trace, the event log or just a
flat file if you need to! You're going to have to know what it thinks
that value is to debug it.

Marc

Aug 20 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
4
by: pjdouillard | last post by:
Hello all, Here is the context of my problem: We have an ASP.NET 1.1 application that has its own application pool setup and that runs under the identity of a NT Domain service account (this...
2
by: Miguel | last post by:
Hi, I'm developing an application in C# with Windows Forms for my company that is similar to the MSN Messenger. This application uses a webservice for registering users, etc... and as 2...
1
by: Steven M. | last post by:
Greetings... I need desperate help with my problem. I guess the solution is related in some way with the cookies getting lost in the authentication process working with some web servers. ...
1
by: svijay | last post by:
hi I have got a strange problem. May I know any solution for this. Here is the detailed description about the problem We have got a mainframe system and also production and development...
22
by: roadrunner | last post by:
Hi, Our website has recently been experiencing some problems under load. We have pinpointed a particular function which slows dramatically when we have these problems. Normally it should execute...
2
by: Bill Nguyen | last post by:
I ran into this error trying to run an app from Publish.htm. I can't find what is wrong with the deployment. Thanks a million Bill -------- PLATFORM VERSION INFO
2
by: Sin Jeong-hun | last post by:
I created a windows form application. It has a Threading.Timer and when the timer ticks it does some work and show a popup window. The problem is that while this program is running if the user...
6
by: Tony Johansson | last post by:
Hello! We have a C#.ASP.NET application that runs on a IIS 6. The application contains actually several asp pages but there is no GUI. The application receive an xml file that is processed....
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.