?
Solved

Having Problems Updating SQL database with C#

Posted on 2003-03-05
7
Medium Priority
?
216 Views
Last Modified: 2012-06-27
Hi,

I am having trouble with my SQL datapase.  I am using a combobox with a list of items to set the info that will be selected.  All the code snipets I am using are below.

Update Command:
sqlAdmin.UpdateCommand.CommandText="UPDATE UserProfiles SET Password = @Password, frmAdmin1 = @frmAdmin1 WHERE (Login = @Login)";


Program Content:
private void boxLogin_SelectedIndexChanged(object sender, System.EventArgs e)
{
     txtFirst.DataBindings.Clear();
     txtLast.DataBindings.Clear();
     txtPWD.DataBindings.Clear();
     sqlAdmin.SelectCommand.Parameters["@Login"].Value = boxLogin.Text;
     Profiles.Clear();
     sqlAdmin.Fill(Profiles);
     txtFirst.DataBindings.Add("Text", Profiles.UserProfiles, "FirstName");
     txtLast.DataBindings.Add("Text", Profiles.UserProfiles, "LastName");
     txtPWD.DataBindings.Add("Text", Profiles.UserProfiles, "Password");
}

private void cmdUpdate_Click(object sender, System.EventArgs e)
{
     sqlAdmin.UpdateCommand.Parameters["@Password"].Value = txtPWD.Text;
     sqlAdmin.UpdateCommand.Parameters["@frmAdmin1"].Value = chkfrmAdmin1.Checked.ToString();
     sqlAdmin.Update(Profiles);
}

When I click the update button and then change the combobox text and then back to the text that should draw this info, I see no changes.  I know this has to be something simple that I am messing up but for the life of me I dont know what.  Please Help.
0
Comment
Question by:WaveWare
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 

Expert Comment

by:szguoxz
ID: 8075976
sqlAdmin.UpdateCommand.Parameters["@Password"].Value = txtPWD.Text;
    sqlAdmin.UpdateCommand.Parameters["@frmAdmin1"].Value = chkfrmAdmin1.Checked.ToString();

In my understanding, you missed a parameter,@login.

Calvin
0
 

Author Comment

by:WaveWare
ID: 8077286
The parameter was set in the cmdLogin_Click section, does it have to be set again in the next section?
0
 

Author Comment

by:WaveWare
ID: 8080189
I just tried setting it again in the cmdLogin_Click section.

The Code now looks like this but there are still no updates.

private void boxLogin_SelectedIndexChanged(object sender, System.EventArgs e)
          {
               txtFirst.DataBindings.Clear();
               txtLast.DataBindings.Clear();
               txtPWD.DataBindings.Clear();
               sqlAdmin.SelectCommand.Parameters["@Login"].Value = boxLogin.Text;
               Profiles.Clear();
               sqlAdmin.Fill(Profiles);
               txtFirst.DataBindings.Add("Text", Profiles.UserProfiles, "FirstName");
               txtLast.DataBindings.Add("Text", Profiles.UserProfiles, "LastName");
               txtPWD.DataBindings.Add("Text", Profiles.UserProfiles, "Password");
          }

          private void cmdUpdate_Click(object sender, System.EventArgs e)
          {
               sqlAdmin.UpdateCommand.Parameters["@Login"].Value = boxLogin.Text;
               sqlAdmin.UpdateCommand.Parameters["@Password"].Value = txtPWD.Text;
               sqlAdmin.UpdateCommand.Parameters["@frmAdmin1"].Value = chkfrmAdmin1.Checked;
          }
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:WaveWare
ID: 8080228
oops, I forgot to type the last line of code in the cmdUpdat_Click section. It's:

sqlAdmimn.Update(Profiles);
0
 

Author Comment

by:WaveWare
ID: 8082174
I found the problem, I used a line of try code to catch what I was doing wrong.  It was a parameter that I didn't realize I created but was causing problems since it was not being passed a value.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11805720
PAQed, with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question