Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 save not saving

Author  Topic 

messi
Starting Member

47 Posts

Posted - 2009-07-16 : 12:07:17
finally the connection string work with me
thanks to afrika

then i mad save btn
but when i save the data it appears in data gridview
but dont appeare in database

save code:

SqlConnection testcon = new SqlConnection(con);
SqlCommand command = new SqlCommand("NewEmp", testcon);
command.CommandType = CommandType.StoredProcedure;
testcon.Open();
command.Parameters.Add("@Name", SqlDbType.NVarChar).Value = txtname.Text;
command.Parameters.Add("@Branch", SqlDbType.NVarChar).Value = txtbranch.Text;
command.Parameters.Add("@Salary", SqlDbType.Int).Value = txtsalary.Text;
command.ExecuteNonQuery();
testcon.Close();
txtbranch.Text = "";
txtname.Text = "";
txtsalary.Text = "";


can any one help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-16 : 13:39:07
can you post the procedure code too? Also did you try running profiler trace to see if save is happening?
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2009-07-16 : 16:01:33
quote:
Originally posted by messi

SqlConnection testcon = new SqlConnection(con);
SqlCommand command = new SqlCommand("NewEmp", testcon);
command.CommandType = CommandType.StoredProcedure;
testcon.Open();
command.Parameters.Add("@Name", SqlDbType.NVarChar).Value = txtname.Text;
command.Parameters.Add("@Branch", SqlDbType.NVarChar).Value = txtbranch.Text;
command.Parameters.Add("@Salary", SqlDbType.Int).Value = txtsalary.Text;
command.ExecuteNonQuery();
testcon.Close();
txtbranch.Text = "";
txtname.Text = "";
txtsalary.Text = "";


can any one help




I dont fully understand what you are trying to do, but the line in red closes the connection while the lines in green, set the textboxes to nothing.

What exactly are you trying to do ???
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2009-07-16 : 16:01:55
also next time, post this in the .net forum not sql
Go to Top of Page

messi
Starting Member

47 Posts

Posted - 2009-07-18 : 00:40:15
quote:
Originally posted by visakh16

can you post the procedure code too? Also did you try running profiler trace to see if save is happening?



thanks for replay
procduer:
Create Proc NewEmp
(@name nvarchar(50),@Branch nvarchar(50),@Salary int)
As
insert into Employees (Emp_Name,Emp_Branch,Emp_Salary) values (@name ,@branch ,@Salary)

Go to Top of Page

messi
Starting Member

47 Posts

Posted - 2009-07-18 : 00:41:42
quote:
Originally posted by afrika

quote:
Originally posted by messi

SqlConnection testcon = new SqlConnection(con);
SqlCommand command = new SqlCommand("NewEmp", testcon);
command.CommandType = CommandType.StoredProcedure;
testcon.Open();
command.Parameters.Add("@Name", SqlDbType.NVarChar).Value = txtname.Text;
command.Parameters.Add("@Branch", SqlDbType.NVarChar).Value = txtbranch.Text;
command.Parameters.Add("@Salary", SqlDbType.Int).Value = txtsalary.Text;
command.ExecuteNonQuery();
testcon.Close();
txtbranch.Text = "";
txtname.Text = "";
txtsalary.Text = "";


can any one help




I dont fully understand what you are trying to do, but the line in red closes the connection while the lines in green, set the textboxes to nothing.

What exactly are you trying to do ???



thanks for replay
i want to free textbox after data saves in DB
Go to Top of Page

messi
Starting Member

47 Posts

Posted - 2009-07-18 : 00:52:42
quote:
Originally posted by afrika

also next time, post this in the .net forum not sql



i am sure i will
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2009-07-18 : 06:53:51
do you get an error message ?
Go to Top of Page
   

- Advertisement -