Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["sree"]);
        cn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = cn;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "select * from vendortab where vuname='" + txtuser.Text + "'and vpwd='" + txtpwd.Text + "' ";
        int cnt;
        cnt = int.Parse(cmd.ExecuteScalar().ToString());
       cn.Close();
        
       if (cnt > 0)
        {
           Session["vuname"] = txtuser.Text;
           Session["vpwd"] = txtpwd.Text;

           Response.Redirect("vendor.aspx");
        }
        else
            Label16.Text="Invalid username or password";
    }
}

error.........
Server Error in '/RENTAL SYSTEM code' Application.
Invalid object name 'vendortab'.
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: Invalid object name 'vendortab'.

Source Error:

Line 29:         cmd.CommandText = "select * from vendortab where vuname='" + txtuser.Text + "'and vpwd='" + txtpwd.Text + "' ";
Line 30:         int cnt;
Line 31:         cnt = int.Parse(cmd.ExecuteScalar().ToString());
Line 32:        cn.Close();
Line 33:         

Source File: h:\RENTAL SYSTEM code\Default.aspx.cs    Line: 31

Stack Trace:

[SqlException (0x80131904): Invalid object name 'vendortab'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1951450
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849003
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2394
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
   System.Data.SqlClient.SqlDataReader.get_MetaData() +83
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteScalar() +139
   _Default.Button1_Click(Object sender, EventArgs e) in h:\RENTAL SYSTEM code\Default.aspx.cs:31
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927
Posted
Updated 4-Jun-13 4:40am
v2
Comments
Ahmed Bensaid 4-Jun-13 10:38am    
Hello,
Your "vendortab" table seems to be inexistent in your database.

Three things:
1) Check your database - it does not contain a table called "vendortab" (as artefakt94 has said).
2) Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
3) Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
 
Share this answer
 
Comments
Manfred Rudolf Bihy 4-Jun-13 11:06am    
1. Is possibly not quite correct. It might just be missing the schema prefix (dbo.). It could of course also be that OP connected to the wrong database. That's why I hinted that setting the "initial catalog" parameter might be helpful.

Cheers!
OriginalGriff 4-Jun-13 11:35am    
Could be - but the schema prefix isn't that often needed - the most likely reason is that the table is spelled wrong. I wanted to get the other things in though, because that kind of ignorance is too prevalent, and too dangerous.
Either the table you named is not present or you need to prefix it with the correct schema ( i.e.: dbo.vendortab). Another thing altogether is that maybe you need to set the Initial Catalog[^] parameter in your connectionstring, which can't be seen in your example since it is in your application configuration file (which is a good thing).

Regards
— Manfred
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900