Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Having Problems Updating SQL database with C#

Posted on 2003-03-05
7
Medium Priority
?
217 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
  • 4
6 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Loops Section Overview
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

564 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