TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sawass sawass
NA
36
23.6k
Exception database
Jun 7 2011 9:02 AM
I have l'exception:
" System.NullReferenceException: Object reference not set to an instance of an object."
when I debug this code:
private void bt_valider_Click(object sender, System.EventArgs e)
{
OdbcConnection cn = new OdbcConnection("DSN=cp22");
int rs1;
try
{
cn.Open();
}
catch
{
MessageBox.Show("Failed to connect to data source");
}
finally
{
OdbcCommand comm;
comm = new OdbcCommand("select * from utilisateur where login=?", cn);
comm.Parameters.Add("login", login.Text);
OdbcDataReader rs;
try
{
rs = comm.ExecuteReader();
if (rs.Read())
{
if (rs.GetString(1) == pass.Text)
{
rs.Close();
OdbcCommand cmd1 = new OdbcCommand("update utilisateur set login=?,mot_de_passe=?,niveau=? where login=?", cn);
// cmd1.Parameters.Add("login", login_new.Text)
cmd1.Parameters.Add( "mot_de_passe", pass_new.Text);
if (type_new.SelectedItem.ToString() == "")
cmd1.Parameters.Add("type", "u");
if (type_new.SelectedItem.ToString() == "Administrateur")
cmd1.Parameters.Add("type", "a");
if (type_new.SelectedItem.ToString() == "utilisateur")
cmd1.Parameters.Add("type", "u");
cmd1.Parameters.Add("", login.Text);
rs1 = cmd1.ExecuteNonQuery();
MessageBox.Show(this, "User modified", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
login.Text = "";
pass.Text = "";
login_new.Text = "";
pass_new.Text = "";
}
else
MessageBox.Show(this, "Invalid old password ", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
MessageBox.Show(this, "User does not exist", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception eo)
{
// MessageBox.Show(this, "Error System", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
login.Text = eo.ToString();
}
}
cn.Close();
}
Is anyone can help me please ant thnks for your reply.
Reply
Answers (
9
)
Empty string from passing data value between windows forms
Please Help - Really Easy For You Guys - String incorrect Format