I am having a hard time getting my registration form to connect to my database via a stored procedure. Any help would be appreciated. The code is listed below
protectedvoid submit_Click(object sender,EventArgs e){
SqlConnection connection =newSqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);
SqlCommand command =newSqlCommand("GE_sp_INSERT_USER", connection);
command.Parameters.Add("@.FirstName",SqlDbType.NVarChar).Value = txtFirstName.Text;command.Parameters.Add("@.LastName",SqlDbType.NVarChar).Value = txtLastName.Text;
command.Parameters.Add("@.UserName",SqlDbType.NVarChar).Value = txtUserName.Text;command.Parameters.Add("@.Password",SqlDbType.NVarChar).Value = txtPassword.Text;
command.Parameters.Add("@.PhoneNumber",SqlDbType.NVarChar).Value = txtPhoneNumber.Text;command.Parameters.Add("@.EmailAddress",SqlDbType.NVarChar).Value = txtEmailAddress.Text;
command.Parameters.Add("@.Address",SqlDbType.NVarChar).Value = txtAddress.Text;command.Parameters.Add("@.City",SqlDbType.NVarChar).Value = txtCity.Text;
command.Parameters.Add("@.State",SqlDbType.NVarChar).Value = txtState.Text;command.Parameters.Add("@.ZipCode",SqlDbType.NVarChar).Value = txtZipCode.Text;connection.Open();
command.ExecuteNonQuery();
connection.Dispose();
}
ALTER PROCEDUREdbo.GE_sp_INSERT_USER
(
@.FirstNamenvarchar(50),@.LastNamenvarchar(50),
@.UserNamenvarchar(50),@.Passwordnvarchar(50),
@.PhoneNumbernvarchar(50),@.EmailAddressnvarchar(50),
@.Addressnvarchar(50),@.Citynvarchar(50),
@.Statenvarchar(50),@.ZipCodenvarchar(50))
AS
INSERT INTOUSERS(FirstName, LastName, UserName, Password, PhoneNumber, EmailAddress, Address, City, State, ZipCode)
VALUES
(@.FirstName, @.LastName, @.UserName, @.Password, @.PhoneNumber, @.EmailAddress, @.Address, @.City, @.State, @.ZipCode)
RETURN
You say you are having a hard time "connecting" to your database. What exactly is the problem you're having? Are you getting an error?
|||You need to set the CommandType:
command.CommandType =CommandType.StoredProcedure;
|||I have added the code below to my code - I placed it right below my sqlCommand. - it still does not work. the error says it cannot find the stored procedure. The webconfig looks correct.
SqlCommand command =newSqlCommand("GE_sp_INSERT_USER", connection);command.CommandType =CommandType.StoredProcedure;
thanks for your help|||That error message has meaning.
Try this:
SqlCommand command =newSqlCommand("dbo.GE_sp_INSERT_USER", connection);
|||
That did not work either. Below is my webconfig - I may be missing something easy.
<connectionStrings>
<addname="myConnectionString"connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\gevjen.mdf;Integrated Security=True;User Instance=True"providerName="System.Data.SqlClient"/></connectionStrings>
thanks again for sticking with this to help me out...
|||A few things
1) Is this connection string working somewhere else in your application?
2) If you connect to your db manually and execute the command do you get any result?
|||hey i am too getting a hard time in making connection to sqlserver,like i have made a connection object and its working but when i reach the open function nothing works,i had been working over this since last 4 days!please guide me how to do it!
|||The database works elsewhere and the stored procedure works as well. I am missing something easy I believe within the connection or webconfig.|||
gevjen:
The database works elsewhere and the stored procedure works as well. I am missing something easy I believe within the connection or webconfig.
Could you copy and paste the actual error message, and the show the line that causes it?
|||
kamna:
hey i am too getting a hard time in making connection to sqlserver...
This should help you:http://www.mikesdotnetting.com/Article.aspx?ArticleID=69
sql
No comments:
Post a Comment