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
Satish BhatPosted Aug 5, 2011, 9:11 AM
Otherwise you can call
posttext.UpdateCommand = postname;
posttext.UpdateCommand.ExecuteNonQuery();
shams khanPosted Aug 5, 2011, 7:43 AM
blase satiatePosted May 21, 2011, 9:51 AM
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
}
VulpesPosted May 21, 2011, 8:58 AM
As there doesn't appear to be a primary key for your table, I'd try setting one - username perhaps.
blase satiatePosted May 21, 2011, 8:22 AM
Dorababu MekaPosted May 21, 2011, 7:54 AM
blase satiatePosted May 21, 2011, 7:35 AM
{
//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
}
blase satiatePosted May 21, 2011, 7:31 AM
yes, i do it - not happened, the same problem.
I write to the database like this: "qwerty" and "asdfg"
Suthish NairPosted May 21, 2011, 7:26 AM
blase satiatePosted May 21, 2011, 7:13 AM
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 NairPosted May 21, 2011, 6:57 AM
Suthish NairPosted May 21, 2011, 6:54 AM
blase satiatePosted May 21, 2011, 6:47 AM
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 NairPosted May 21, 2011, 6:36 AM
blase satiatePosted May 21, 2011, 6:31 AM
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 NairPosted May 21, 2011, 6:03 AM
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