Hi ,
I have a form in which I show UserInfo from the DataBase using Stored
Procedure and I populate 5 TextBox controls with this information in this
way:
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
SqlConnection conn = new SqlConnection(" Data Source=BLEK;Ini tial
Catalog=Estate; User ID=haha; Password=****** *");
SqlDataAdapter dad = new SqlDataAdapter( "prRTUSERIN FO", conn);
dad.SelectComma nd.CommandType= CommandType.Sto redProcedure;
conn.Open();
dad.SelectComma nd.Parameters.A dd(new SqlParameter("@ USRNAM",
SqlDbType.VarCh ar,20));
dad.SelectComma nd.Parameters["@USRNAM"].Value =
Session["usrName"].ToString();
DataSet ds = new DataSet();
dad.Fill(ds, "Users");
NameTB.Text=ds. Tables["Users"].Rows[0][3].ToString();
PhoneTB.Text=ds .Tables["Users"].Rows[0][5].ToString();
AddressTB.Text= ds.Tables["Users"].Rows[0][6].ToString();
CityTB.Text=ds. Tables["Users"].Rows[0][4].ToString();
EmailTB.Text=ds .Tables["Users"].Rows[0][7].ToString();
usrID=Int32.Par se(ds.Tables["Users"].Rows[0][0].ToString());
conn.Close();
}
The user could see the info and change the Text in the TextBoxes.
On the same form I have an InsertButton and when I click it I would like to
update the information in the DataBase with the changed information. If the
info is not changed and the Button is clicked I update the DataBase with the
same info from The TextBoxes. The problem is that when I have tried to
change the text in the TextBoxes and than I clicked the Button nothing
happens. The same info was in the TexBoxes, I mean the info which was in the
TextBoxes when the page was loaded for the first time.
Here it is the code of the Button_Click:
private void InsertBtn_Click (object sender, System.EventArg s e)
{
SqlConnection conn = new SqlConnection(" Data Source=BLEK;Ini tial
Catalog=Estate; User ID=haha; Password=****** ");
SqlDataAdapter dada = new SqlDataAdapter( );
dada.UpdateComm and = new SqlCommand("UPD ATE HAHA.USERS SET
RealName=@NAME, UserCity=@CITY, UserPhone=@PHON E,UserAddr=@ADD R,UserEmail=@EM L
WHERE Username=@USRNA ME",conn);
dada.UpdateComm and.CommandType = CommandType.Tex t;
dada.UpdateComm and.Parameters. Add(new SqlParameter("@ NAME",
SqlDbType.VarCh ar,64));
dada.UpdateComm and.Parameters["@NAME"].Value = NameTB.Text.Tri m();
dada.UpdateComm and.Parameters. Add(new SqlParameter("@ CITY",
SqlDbType.VarCh ar,20));
dada.UpdateComm and.Parameters["@CITY"].Value = CityTB.Text.Tri m();
dada.UpdateComm and.Parameters. Add(new SqlParameter("@ PHONE",
SqlDbType.VarCh ar,16));
dada.UpdateComm and.Parameters["@PHONE"].Value = PhoneTB.Text.Tr im();
dada.UpdateComm and.Parameters. Add(new SqlParameter("@ ADDR",
SqlDbType.VarCh ar,74));
dada.UpdateComm and.Parameters["@ADDR"].Value = AddressTB.Text. Trim();
dada.UpdateComm and.Parameters. Add(new SqlParameter("@ EML",
SqlDbType.VarCh ar,64));
dada.UpdateComm and.Parameters["@EML"].Value = EmailTB.Text.Tr im();
dada.UpdateComm and.Parameters. Add(new SqlParameter("@ USRNAME",
SqlDbType.VarCh ar,20));
dada.UpdateComm and.Parameters["@USRNAME"].Value =
Session["usrName"].ToString();
conn.Open();
dada.UpdateComm and.ExecuteNonQ uery();
conn.Close();
}
Could you tell me where I am wrong?
Thank you in advance!
Viktor
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.744 / Virus Database: 496 - Release Date: 24.8.2004 a.