forum

Home / DeveloperSection / Forums / Updating database for specific user

Updating database for specific user

Aaron Douglas178819-Jun-2013
Hi Expert, 

I'm trying to updata my sql database for a specific name, and the following code is not working. Any ideas why?

Here is what I am doing on the button click:

string person = listBox2.SelectedItem.ToString();
string memberStatus = "platinum";
string conn = "Data Source=.;Initial Catalog=myDB;Integrated Security=True";
using (SqlConnection connection = new SqlConnection(conn))
{
    SqlCommand cmd = new SqlCommand("UPDATE Client Set Role = @Status  WHERE Name = @name");
    cmd.CommandType = CommandType.Text;
    cmd.Connection = connection;
    cmd.Parameters.AddWithValue("@Status", memberStatus);
    cmd.Parameters.AddWithValue("@name", person);
    connection.Open();
    cmd.ExecuteNonQuery();  
}

When I check the database, the Client's Role has not been updated. And when I debug, the value of person is "System.Data.DataRowView" Why is that? How can i fix it?


Updated on 19-Jun-2013

Can you answer this question?


Answer

1 Answers

Liked By