Hi,
I'm new to .NET.
when I 'm trying to execute the following code I got an InvalidCastException error
string FirstName = "txtFirstName";// get username from user
string SecondName = "txtSecondName" ;// get password from user
SqlConnection conn = new SqlConnection("Data Source=localhost;Database=db2;Integrated Security=SSPI");
SqlCommand command = new SqlCommand("InsertUser", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFirstName;
command.Parameters.Add("@SecondName", SqlDbType.VarChar).Value = txtSecondName;
conn.Open();
int rows = command.ExecuteNonQuery();//showing error in this line.
conn.Close();
I'm using the following stored procedure
ALTER PROCEDURE dbo.InsertUser
(
@FirstName varchar(50),
@SecondName varchar(50)
)
AS
INSERT into details VALUES(@FirstName,@SecondName)
What is causing this error? What can I do? Can anyone help me....
I'm new to .NET.
when I 'm trying to execute the following code I got an InvalidCastException error
string FirstName = "txtFirstName";// get username from user
string SecondName = "txtSecondName" ;// get password from user
SqlConnection conn = new SqlConnection("Data Source=localhost;Database=db2;Integrated Security=SSPI");
SqlCommand command = new SqlCommand("InsertUser", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFirstName;
command.Parameters.Add("@SecondName", SqlDbType.VarChar).Value = txtSecondName;
conn.Open();
int rows = command.ExecuteNonQuery();//showing error in this line.
conn.Close();
I'm using the following stored procedure
ALTER PROCEDURE dbo.InsertUser
(
@FirstName varchar(50),
@SecondName varchar(50)
)
AS
INSERT into details VALUES(@FirstName,@SecondName)
What is causing this error? What can I do? Can anyone help me....