Error converting data type nvarchar to numeric.
On line sdr.Read();
protected void Button1_Click(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Id, vst_nm, idtyp,idnm,fa_hu_nm,gndr,phn,vstd_dt,crnt_add,pur_pos FROM vstr2 WHERE idnm = " + txtconfirmpass6.Text.Trim() + ""))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
sdr.Read();
txtcurrentpass.Text = sdr["Id"].ToString();
TextBox2.Text = sdr["vst_nm"].ToString();
txtconfirmpass.Text = sdr["idtyp"].ToString();
txtconfirmpass6.Text = sdr["idnm"].ToString(System.Data.SqlDbType.Decimal);
txtconfirmpass0.Text = sdr["fa_hu_nm"].ToString();
txtconfirmpass1.Text = sdr["gndr"].ToString();
txtconfirmpass3.Text = sdr["phn"].ToString();
txtconfirmpass2.Text = sdr["vstd_dt"].ToString();
txtconfirmpass4.Text = sdr["crnt_add"].ToString();
txtconfirmpass5.Text = sdr["pur_pos"].ToString();
}
con.Close();
}
}
}
CREATE TABLE [dbo].[vstr2] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[emp_id] NVARCHAR (10) NULL,
[emp_nm] VARCHAR (500) NULL,
[dept] VARCHAR (100) NULL,
[vst_nm] VARCHAR (1000) NULL,
[idtyp] NCHAR (1000) NULL,
[idnm] NCHAR (1000) NULL,
[fa_hu_nm] VARCHAR (1000) NULL,
[gndr] VARCHAR (50) NULL,
[phn] NCHAR (12) NULL,
[crnt_add] VARCHAR (5000) NULL,
[pur_pos] VARCHAR (5000) NULL,
[vstd_dt] DATE NULL,
[is_dlt] VARCHAR (3) DEFAULT ('No') NULL,
[is_vstd] VARCHAR (30) DEFAULT ('No') NULL,
[cisf_out_flag] VARCHAR (3) DEFAULT ('No') NULL,
[cisf_in_flag] VARCHAR (3) DEFAULT ('No') NULL,
[cisf_out_flag_time] VARCHAR (30) DEFAULT ('No') NULL,
[cisf_in_flag_time] VARCHAR (30) DEFAULT ('No') NULL,
CONSTRAINT [PK_vstr2] PRIMARY KEY CLUSTERED ([Id] ASC)
);