Hi!
As part of my school training I'm experimenting with the
following:
When trying to insert new username and password into a sql
database
(SQL 2000) through C# code I did the following:
private void btnInsertWithStoredProcedure_Click(object
sender,
System.EventArgs e)
{
//Outer exception, nothing succeeded
try
{
SqlConnection con = new SqlConnection
("server=localhost;database=Users;uid=geir;pwd=geir&quo
t;);
con.Open();
//Inner exception. ExecuteNonQuery failed
try
{
//Addressing stored
procedure
SqlCommand cmdIns = new
SqlCommand("InsUnameAndPword",con);
cmdIns.CommandType = CommandType.StoredProcedure;
cmdIns.Parameters.Add(" Username",SqlDbType.VarChar,8,txtUsername.Text.T
rim());
cmdIns.Parameters.Add(" Password",SqlDbType.VarChar,8,txtPassword.Text.T
rim());
cmdIns.ExecuteNonQuery();
}
catch(SqlException ex)
{
lblInfo.Text = "ExecuteNonQuery failed because:
n" +
"n" +
ex.Message;
}
finally
{
//Refresh datagrid
and blank
out textboxes on form
dgUsers.Refresh();
txtUsername.Text = "";
txtPassword.Text = "";
con.Close();
lblInfo.Text = "Updated database with new user and
password!";
}//End Inner exception
con.Close();
}
catch(Exception ex)
{
lblInfo.Text = "Errormessage: " + ex.Message;
}//End Outer Exception
}
Anybody that could help me out explaining what I miss here?
This is just a simple training case in order to understand
the 'rhytm'
of stored procedures.
I use a sql 2000 database with three fields:
UserID int(4)
Username varchar(8)
Password varchar(8)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---
|