1 Replies - 4175 Views - Last Post: 21 October 2009 - 07:04 PM Rate Topic: -----

#1 husna_   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 07-September 09

Failed to convert parameter value from a ListItem to a String

Posted 21 October 2009 - 06:18 PM

I am trying to insert certain values into the table using SQL server 2005.
I have used textbox, label and listbox.
But by doing so, I have an error that states "Failed to convert parameter value from a ListItem to a String"

How do i solve this?
try
			{
				//Create an insert command
				SqlCommand insertCmd = new SqlCommand("INSERT INTO Account(CustID, Name, TelExtension, Email, Password, AccountType, Status) VALUES " + "(@StaffID, @Name, @TelExtension, @Email, @Password, @StaffType, @Status); SELECT * FROM StaffAccount", sqlCon);

			//Add the parameters to the command
			insertCmd.Parameters.Add("@CustID", SqlDbType.VarChar, 20);
			insertCmd.Parameters.Add("@Name", SqlDbType.VarChar, 50);
			insertCmd.Parameters.Add("@TelExtension", SqlDbType.NChar, 20);
			insertCmd.Parameters.Add("@Email", SqlDbType.VarChar, 50);
			insertCmd.Parameters.Add("@Password", SqlDbType.VarChar, 25);
			insertCmd.Parameters.Add("@AccountType", SqlDbType.VarChar, 2);
			insertCmd.Parameters.Add("@Status", SqlDbType.VarChar, 1);

			//Set the parameters
			insertCmd.Parameters["@CustID"].Value = StaffID_txt.Text;
			insertCmd.Parameters["@Name"].Value = Name_txt.Text;
			insertCmd.Parameters["@TelExtension"].Value = telExtension_txt.Text;
			insertCmd.Parameters["@Email"].Value = email_txt.Text;
			insertCmd.Parameters["@Password"].Value = password_txt.Text;
			insertCmd.Parameters["@AccountType"].Value = StaffType_LB.SelectedItem;
			insertCmd.Parameters["@Status"].Value = status_lblvalue.Text;




Is This A Good Question/Topic? 0
  • +

Replies To: Failed to convert parameter value from a ListItem to a String

#2 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: Failed to convert parameter value from a ListItem to a String

Posted 21 October 2009 - 07:04 PM

Put .ToString() on the end of your StaffType_LB.SelectedItem
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1