Dear Sir,
i want to display mobile number from table to Label1 but i have getting mention error. i don't want any changes in table structure.
Server Error in '/NEW_OCMS' Application.
Conversion failed when converting the nvarchar value 'civiladmin' to data type int.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting the nvarchar value 'civiladmin' to data type int. Source Error:
Line 40: SqlCommand cmd = new SqlCommand("Select * from emp WHERE EMP_ID=" + lblName.Text + "", con);
Line 41: SqlDataReader dr = cmd.ExecuteReader();
Line 42: if (dr.Read())
Line 43: {
Line 44: Label1.Text = dr["PHONE_MOB"].ToString();
|
Source File: c:\inetpub\wwwroot\OCMS\OCMS\It_Comp.aspx.cs Line: 42 Stack Trace:
[SqlException (0x80131904): Conversion failed when converting the nvarchar value 'civiladmin' to data type int.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +2582782
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +6033430
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +297
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4291
System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows) +242
System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more) +275
System.Data.SqlClient.SqlDataReader.Read() +35
OCMS.It_Comp.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\OCMS\OCMS\It_Comp.aspx.cs:42
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +52
System.Web.UI.Control.OnLoad(EventArgs e) +97
System.Web.UI.Control.LoadRecursive() +61
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +693
|
namespace OCMS
{
public partial class It_Comp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string IPAdd = string.Empty;
IPAdd = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(IPAdd))
IPAdd = Request.ServerVariables["REMOTE_ADDR"];
lblIP.Text = IPAdd;
if (!Page.IsPostBack)
{
ReadOnlyTextBox.Text = "IT COMPLAINT";
lblName.Text = " " + Request.QueryString["EmpId"] + "";
BindGrid();
this.StoreVisitorIPDetails();
}
SqlConnection con = new SqlConnection("Data Source=10.1.246.4;Initial Catalog=OCMS;User ID=dba_ntpc_meja_intranet;Password=alpha$890;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
con.Open();
SqlCommand cmd = new SqlCommand("Select * from emp WHERE EMP_ID=" + lblName.Text + "", con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Label1.Text = dr["PHONE_MOB"].ToString();
}
}
private void StoreVisitorIPDetails()
{
string employeeId = lblName.Text.Trim();
string ipAddress;
// Gets Client IP Address
ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipAddress == "" || ipAddress == null)
ipAddress = Request.ServerVariables["REMOTE_ADDR"];
string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("StoreIPAddressDetails");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@IPAddress", ipAddress);
cmd.Parameters.AddWithValue("@EMP_ID", employeeId);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
con.Dispose();
}
}
}