Ronok Bhowmik

Ronok Bhowmik

  • NA
  • 37
  • 30.6k

How to convert varchar into data type int

Jan 11 2014 2:21 AM
I have one textbox ,one combobox and password box.When all the three values are matched to the database value then i can login the next window.But it creates an error like this:Input string was not in a correct format. And my sample code is: 
 
SqlConnection conn = new SqlConnection(dataconnection);
conn.Open();
SqlCommand cmd = new SqlCommand("uspLogin", conn);
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ProvostName",ProvostNametextbox.Text);
cmd.Parameters.AddWithValue("@ProfessorRank",Convert.ToInt32(ProvostRankComboBox.Text));
cmd.Parameters.AddWithValue("@Password", ProvostPasswordtextbox.Password);
//cmd.ExecuteNonQuery();
SqlDataReader sdr = cmd.ExecuteReader();
if ((sdr.Read() == true))

{
MainWindow1 main = new MainWindow1();
main.Show();
this.Close();
}

else
{
MessageBox.Show("Sorry,try again!");

}
----------------
My stored procedure is:
USE [MyHallDatabase]
GO
/****** Object: StoredProcedure [dbo].[uspLogin] Script Date: 01/11/2014 13:20:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[uspLogin]
(
@ProvostName nvarchar(20),
@ProfessorRank nvarchar(20),
@Password int
)
As
begin
SELECT *
FROM Provosts
WHERE ProvostName=@ProvostName AND ProfessorRankId=@ProfessorRank AND Password=@Password
end

--------------- Please Help me.Thanks in advance.

Answers (1)