0 Replies - 766 Views - Last Post: 09 February 2009 - 11:28 PM Rate Topic: -----

#1 sandeepparekh9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-January 09

ado.net with c#- updates are not made to sql database

Posted 09 February 2009 - 11:28 PM

hi
there i have created a simple program from storing login username and password.. in sql database..

table name: [/b]login
fieds: 1) urname 2) pass

there are two buttons NEW, and SAVE..
and two TextBoxs named: username, password

form load event;
	   private void Form1_Load(object sender, EventArgs e)
		{
			conn = new SqlConnection("Server=server;Database=test;uid=sa;pwd=goldstar");
			
			dslogin = new DataSet();
			dalogin = new SqlDataAdapter("select urname, pass from login", conn);
			SqlCommandBuilder cmdbld = new SqlCommandBuilder(dalogin);
			conn.Open();
			dalogin.Fill(dslogin, "login");
			dataGridView1.DataSource = dslogin;
			dataGridView1.DataMember = "login";
			currmgr = (CurrencyManager)this.BindingContext[dslogin.Tables["login"]];
			textBox1.DataBindings.Add("Text", dslogin.Tables["login"], "urname");
			textBox2.DataBindings.Add("Text", dslogin.Tables["login"], "pass");

		}



new button code:
textBox1.Clear();
textBox2.Clear();



SAVE Button code:
			dalogin.InsertCommand = conn.CreateCommand();
			dalogin.InsertCommand.CommandText = "insert into login " + "(urname,pass) " + "values " + "(?,?)";
			dalogin.InsertCommand.Parameters.Add("urname", SqlDbType.NVarChar, 50, "urname");
			dalogin.InsertCommand.Parameters.Add("pass", SqlDbType.NVarChar, 50, "pass");
			DataTable datatable = dslogin.Tables[0];
			DataRow rw = datatable.NewRow();
			rw["urname"] = textBox1.Text.Trim();
			rw["pass"] = textBox2.Text.Trim();

			try
			{
				dslogin.Tables["login"].Rows.Add(rw);
				dalogin.Update(dslogin, "login");
				dslogin.AcceptChanges();
				Application.DoEvents();
			}
			catch (Exception x)
			{
			}



WHEN i press the save button my changes are shown to the gridview but when i close the application and restart it the changes are gone.. they are not there.
and also my changes are not made to my sql database..

This post has been edited by sandeepparekh9: 09 February 2009 - 11:30 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1