Why do I get the error message ‘Object must implement IConvertible’. How can I resolve it

Platform: ASP.NET| Category: Basic

The common cause for this error is specifying a control as a SqlParameter’s Value instead of the control’s text value.

For example, if you write code as below you’ll get the above error:

VB.NET


Dim nameParameter As SqlParameter = command.Parameters.Add('@name', SqlDbType.NVarChar, 50)
nameParameter.Value = txtName

C#


SqlParameter nameParameter = command.Parameters.Add('@name', SqlDbType.NVarChar, 50);
nameParameter.Value = txtName ;

To resolve it, specify the control’s Text property instead of the control itself.

VB.NET


nameParameter.Value = txtName.Text

C#


nameParameter.Value =txtName.Text;

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.