Hi,I have a login form that contains a textbox,a combobox and a password box.when all the information matches with the database it allows me to login.But i am facing the problem and it says:Input string was not in a correct format.
Here is my code:
{
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);
SqlDataReader sdr = cmd.ExecuteReader();
if ((sdr.Read() == true))
{
MainWindow1 main = new MainWindow1();
main.Welcometextblock.Text = ProvostNametextbox.Text;
main.Entertextblock.Text = ProvostRankComboBox.Text;
main.Show(); //Sending value from one form to another form.
Close();
}
else
{
MessageBox.Show("Sorry,try again!");
}
And my stored procedure is:
USE [MyHallDatabase]
GO
/****** Object: StoredProcedure [dbo].[uspLogin] Script Date: 01/17/2014 03:01:49 ******/
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
plz help me to fix it.thanks in advance.
Loading

VulpesPosted Jan 17, 2014, 7:22 AM
Biswa Pujarini MohapatraPosted Jan 17, 2014, 3:24 AM
Biswa Pujarini MohapatraPosted Jan 17, 2014, 3:14 AM
1) what is the datatype of professor rank column in database
2) what is the text and value you are binding in combobox
if possible can you give your table format
Chandan Kr MadalPosted Jan 17, 2014, 3:09 AM
Ronok BhowmikPosted Jan 17, 2014, 2:08 AM
Biswa Pujarini MohapatraPosted Jan 17, 2014, 1:55 AM
use this
cmd.Parameters.AddWithValue("@ProfessorRank",Int32.Parse(ProvostRankComboBox.Text));
Ronok BhowmikPosted Jan 17, 2014, 1:48 AM
Thanks in Advance.
Biswa Pujarini MohapatraPosted Jan 17, 2014, 1:37 AM
cmd.Parameters.AddWithValue("@ProfessorRank",Convert.ToInt32(ProvostRankComboBox.Text));
convert the combobox text to Int as in your Store procedure @professorRank is Int datatype
Hope it helps
Ronok BhowmikPosted Jan 17, 2014, 1:25 AM
My 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.ToString(ProvostRankComboBox.Text));
cmd.Parameters.AddWithValue("@Password", ProvostPasswordtextbox.Password);
SqlDataReader sdr = cmd.ExecuteReader();
if ((sdr.Read() == true))
{
MainWindow1 main = new MainWindow1();
main.Welcometextblock.Text = ProvostNametextbox.Text;
main.Entertextblock.Text = ProvostRankComboBox.Text;
main.Show(); //Sending value from one form to another form.
Close();
}
else
{
MessageBox.Show("Sorry,try again!");
}
}
My stored Procedure is:
USE [MyHallDatabase]
GO
/****** Object: StoredProcedure [dbo].[uspLogin] Script Date: 01/17/2014 12:14:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[uspLogin]
(
@ProvostName nvarchar(20),
@ProfessorRank int,
@Password nvarchar(20)
)
As
begin
SELECT *
FROM Provosts
WHERE ProvostName=@ProvostName AND ProfessorRank=@ProfessorRank AND Password=@Password
end
Help me .
VulpesPosted Jan 16, 2014, 5:03 PM
@ProvostName nvarchar(20),
@ProfessorRank int,
@Password nvarchar(20)
I take it that the ProfessorRank combobox contains a series of numbers.