what is wrong here? no error shows and nothing happens (the variables are not empty - I checked)
SqlCommand postname = new SqlCommand("UPDATE sites SET username=@username, userpass=@userpass WHERE useralias=@useralias",connection);
connection.Open();
SqlDataAdapter posttext = new SqlDataAdapter();
postname.Parameters.Add("@username", SqlDbType.NVarChar, 50, username);
postname.Parameters.Add("@userpass", SqlDbType.NVarChar, 50, userpass);
postname.Parameters.Add("@useralias", SqlDbType.NVarChar, 50, theAlias);
posttext.UpdateCommand = postname;
or am I not doing? I need to update the column to other values??.
I translated the interpreter, so I apologize if poorly understood.
Loading

Suthish NairRank #92 · 22.8K reputationPosted May 21, 2011, 2:03 AM EDT
connection.Open();
SqlCommand postname = new SqlCommand("UPDATE sites SET username=@username, userpass=@userpass WHERE useralias=@useralias",connection);
SqlDataAdapter posttext = new SqlDataAdapter();
postname.Parameters.Add("@username", SqlDbType.NVarChar, 50, "username");
postname.Parameters.Add("@userpass", SqlDbType.NVarChar, 50, "userpass");
postname.Parameters.Add("@useralias", SqlDbType.NVarChar, 50, "useralias");
posttext.UpdateCommand = postname;
Put a breakpoint and check the parameters value.
Also, check the Select statement for above updation
blase satiate15 reputationPosted May 21, 2011, 2:31 AM EDT
using (SqlConnection connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=....;Integrated Security=True;User Instance=True;"))
{
//UPDATE
connection.Open();
SqlCommand postname = new SqlCommand("UPDATE sites SET username=@username, userpass=@userpass WHERE useralias=@useralias", connection);
SqlDataAdapter posttext = new SqlDataAdapter();
postname.Parameters.Add("@username", SqlDbType.NVarChar, 50, username);
postname.Parameters.Add("@userpass", SqlDbType.NVarChar, 50, userpass);
postname.Parameters.Add("@useralias", SqlDbType.NVarChar, 50, theTable);
posttext.UpdateCommand = postname;
LGN.Text = username; PSW.Text = userpass; //check values
//SELECT
SqlCommand getname = new SqlCommand("SELECT usersite, username, userpass FROM sites WHERE useralias='" + theTable + "'", connection);
SqlDataReader gettext = getname.ExecuteReader();
while(gettext.Read())
{
siteLabel.Text = String.Format("New auth for {0}:", gettext[0]);
loginLabel.Text = String.Format("{0}", gettext[1]);
passLabel.Text = String.Format("{0}", gettext[2]);
}
gettext.Close();
}
in the db table "Sites" has not changed.
"SELECT" works well. shows the values ??from the table that there are
Suthish NairRank #92 · 22.8K reputationPosted May 21, 2011, 2:36 AM EDT
blase satiate15 reputationPosted May 21, 2011, 2:47 AM EDT
yes.. UPDATE code is not correct,
i see: all is correct, but all is not work.
only "SELECT" good work.
PS:
>"SELECT works well. shows the values ??from the table that there are"
correctly write*:
"SELECT works well. shows the values ??from the table that there are"*
Suthish NairRank #92 · 22.8K reputationPosted May 21, 2011, 2:54 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted May 21, 2011, 2:57 AM EDT
blase satiate15 reputationPosted May 21, 2011, 3:13 AM EDT
type NVarChar is default, i must change it? on what?
connection.Open();
SqlCommand postname = new SqlCommand("UPDATE sites SET username='"+username+"', userpass='"+userpass+"' WHERE useralias='"+theTable+"'", connection);
SqlDataAdapter posttext = new SqlDataAdapter();
postname.Parameters.Add("@username", SqlDbType.NVarChar, 50, username); // del it
postname.Parameters.Add("@userpass", SqlDbType.NVarChar, 50, userpass); //del it
postname.Parameters.Add("@useralias", SqlDbType.NVarChar, 50, theTable); //del it
posttext.UpdateCommand = postname;
LGN.Text = username; PSW.Text = userpass;
I deleted these parameters. and changed in a database of these types of data to "Varchar", to"text", to "ntext" - nothing happened. what should be changed?
Suthish NairRank #92 · 22.8K reputationPosted May 21, 2011, 3:26 AM EDT
blase satiate15 reputationPosted May 21, 2011, 3:31 AM EDT
yes, i do it - not happened, the same problem.
I write to the database like this: "qwerty" and "asdfg"
blase satiate15 reputationPosted May 21, 2011, 3:35 AM EDT
{
//UPDATE
connection.Open();
SqlCommand postname = new SqlCommand("UPDATE sites SET username='"+username+"', userpass='"+userpass+"' WHERE useralias='"+theTable+"'", connection);
SqlDataAdapter posttext = new SqlDataAdapter();
posttext.UpdateCommand = postname;
//end UPDATE
//SELECT
SqlCommand getname = new SqlCommand("SELECT usersite, username, userpass FROM sites WHERE useralias='" + theTable + "'", connection);
SqlDataReader gettext = getname.ExecuteReader();
while(gettext.Read())
{
siteLabel.Text = String.Format("New auth for {0}:", gettext[0]);
loginLabel.Text = String.Format("{0}", gettext[1]);
passLabel.Text = String.Format("{0}", gettext[2]);
}
gettext.Close();
//end SELECT
}
Dorababu MekaRank #457 · 5.5K reputationPosted May 21, 2011, 3:54 AM EDT
blase satiate15 reputationPosted May 21, 2011, 4:22 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 21, 2011, 4:58 AM EDT
As there doesn't appear to be a primary key for your table, I'd try setting one - username perhaps.
blase satiate15 reputationPosted May 21, 2011, 5:51 AM EDT
column: 'id'
type: 'int'
and set primary key it.
update it by this query: UPDATE sites SET username='test', userpass='test2' WHERE useralias='qiq'
not work((
full code:
using (SqlConnection connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\stite\\??? ?????????\\visual studio 2010\\Projects\\WebApplication5\\WebApplication5\\App_Data\\Database1.mdf;Integrated Security=True;User Instance=True;"))
{
//UPDATE
connection.Open();
SqlCommand postname = new SqlCommand("UPDATE sites SET username='test', userpass='test2' WHERE useralias='qiq'", connection);
SqlDataAdapter posttext = new SqlDataAdapter();
posttext.UpdateCommand = postname;
//end UPDATE
//SELECT
SqlCommand getname = new SqlCommand("SELECT usersite, username, userpass FROM sites WHERE useralias='" + theTable + "'", connection);
SqlDataReader gettext = getname.ExecuteReader();
while(gettext.Read())
{
siteLabel.Text = String.Format("New auth for {0}:", gettext[0]);
loginLabel.Text = String.Format("{0}", gettext[1]);
passLabel.Text = String.Format("{0}", gettext[2]);
}
gettext.Close();
//end SELECT
}
shams khan10 reputationPosted Aug 5, 2011, 3:43 AM EDT
Satish BhatRank #2,496 · 563 reputationPosted Aug 5, 2011, 5:11 AM EDT
Otherwise you can call
posttext.UpdateCommand = postname;
posttext.UpdateCommand.ExecuteNonQuery();