Click here to Skip to main content
15,916,945 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
table Member:
MemberID | MemberName | Type

Insert query:
ALTER PROCEDURE [dbo].[SavetblMember]

@MemberID varchar (50),
@MemberName varchar (50),
@Type varchar (50)


INSERT INTO tblMember(MemberID, MemberName, Type)
VALUES(@MemberID, @MemberName, @Type)

C# code:(to save the member)
private void btnAdd_Click(object sender, EventArgs e)
                string c = ConfigurationManager.ConnectionStrings["Constr"].ConnectionString;
                SqlConnection conn = new SqlConnection(c);
                SqlCommand cmd = new SqlCommand("SavetblMember", conn);
                cmd.Parameters.Add("@MemberID", SqlDbType.VarChar, 50).Value = metroTextBox1.Text;
                cmd.Parameters.Add("@MemberName", SqlDbType.VarChar, 50).Value = metroTextBox2.Text;
                cmd.Parameters.Add("@Type", SqlDbType.VarChar, 50).Value = CombMemType.Text;


            catch (SqlException ex)
                MetroMessageBox.Show(this, "Error" + ex.Message);

When I try to Add member,update and delete, it throws me Sqlexception: Error procedure or Function 'SavetlMem'expects parameter '@MemberID', which was not supplied.
I put execute statement after the parameter it gives me same error.
I tried by OleDbtype for it but didn't work.
Updated 4-Nov-15 5:11am
AnvilRanger 4-Nov-15 11:28am    
Which error message are you actually getting? The title talks about converting a varchar to an in, but in the body of the question you mention the expected parameter was not supplied error. Please update your question with the appropriate code and error message.
Member 12045962 4-Nov-15 11:29am    
See my solution.. My problem has been solved...

You're executing the query before you're adding the parameters.
Share this answer
Member 12045962 4-Nov-15 10:45am    
No, I changed this because when I execute statement after the parameters it gives me same error.
You're trying to execute the statement before you add the parameters.
Share this answer
Member 12045962 4-Nov-15 10:49am    
No, I changed this because when I execute statement after the parameters it gives me same error.
PIEBALDconsult 4-Nov-15 11:24am    
Well, don't do that. The parameters must be added before executing. And they must not be NULL -- to insert a NULL, set the parameter Value to DBNull.Value -- or you get the same error you have seen.
Member 12045962 4-Nov-15 11:27am    
Look my solution I've added...
Seem to be calling a stored procedure - yet I've never defined my SqlCommand to be a stored procedure:

using (SqlCommand cmd = new SqlCommand("dbo.usp_ClientHistoryItem", conn))
cmd.CommandType = CommandType.StoredProcedure; // add this line to tell ADO.NET it's a stored procedure!!


running perfectly...
Share this answer
PIEBALDconsult 4-Nov-15 11:34am    
Don't answer your own question. Just add that to the question.
Member 12045962 4-Nov-15 11:35am    
Where??? I don't know sorry...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900