| |

VerySource

 Forgot password?
 Register
Search
View: 1336|Reply: 10

Please prawn help, urgent!

[Copy link]

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-2-21 08:30:01
| Show all posts |Read mode
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 billing information_loginpage: System.Web.UI.Page
{
    protected void Page_Load (object sender, EventArgs e)
    {

    }
    protected void Button1_Click (object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection ();
        con.ConnectionString = "Server = 192.168.0.1; database = fapiao; integrated security = true";
        con.Open ();
        SqlCommand cmd = new SqlCommand ();
        cmd.Connection = con;
        cmd.CommandText = "select * from check where tax ID = '" + TextBox1.Text + "'";
        
        SqlDataReader dr = cmd.ExecuteReader ();
        if (dr.Read ())
        {
            Session ["Tax ID"] = TextBox1.Text;
            Response.Redirect ("check.aspx");
        }
        else
        {Response.Write ("<script language = 'javascript'> window.alert ('Your input is incorrect, please re-enter it!'); </ Script>");}
    }
 
}
******************************
The above is the content of my program. When I enter the correct tax ID, I am prompted with SqlDataReader dr = cmd.ExecuteReader (); There is an error on this line, I do n’t understand. I hope you can give instructions and wait online.
Reply

Use magic Report

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-4-29 20:15:01
| Show all posts
The above string to connect to the database may be a bit problem, I want to ask, how to write the connection string when SQLSERVER is on another host? I use the driver, the prompt says it is not supported. Come and help!
Reply

Use magic Report

0

Threads

25

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-5-2 17:30:02
| Show all posts
Post the error message to see.
[Tax ID] What type?
int?
Change '"+ TextBox1.Text +"' to "+ TextBox1.Text +"
Reply

Use magic Report

0

Threads

25

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-5-2 21:45:01
| Show all posts
It is recommended that the landlord not display Chinese in the class name.
Such as: public partial class billing information _loginpage
Reply

Use magic Report

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-5-4 19:45:01
| Show all posts
The tax type I use is the char type, the int type is not large enough, and the double type cannot be found in the system, is it not possible to use char?
'"+ TextBox1.Text +"' has double quotes because it is included in the select statement

[SqlException (0x80131904): There is a syntax error near the keyword 'check'. ]
   System.Data.SqlClient.SqlConnection.OnError (SqlException exception, Boolean breakConnection) +177
   System.Data.SqlClient.SqlInternalConnection.OnError (SqlException exception, Boolean breakConnection) +68
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning (TdsParserStateObject stateObj) +199
   System.Data.SqlClient.TdsParser.Run (RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2305
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData () +31
   System.Data.SqlClient.SqlDataReader.get_MetaData () +62
   System.Data.SqlClient.SqlCommand.FinishExecuteReader (SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +294
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1021
   System.Data.SqlClient.SqlCommand.RunExecuteReader (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +314
   System.Data.SqlClient.SqlCommand.RunExecuteReader (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +20
   System.Data.SqlClient.SqlCommand.ExecuteReader (CommandBehavior behavior, String method) +107
   System.Data.SqlClient.SqlCommand.ExecuteReader () +80
   Billing information_loginpage.Button1_Click (Object sender, EventArgs e) in f:\check\Billing information\loginpage.aspx.cs: 28
   System.Web.UI.WebControls.Button.OnClick (EventArgs e) +75
   System.Web.UI.WebControls.Button.RaisePostBackEvent (String eventArgument) +97
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent (String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent (IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent (NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain (Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-6 19:15:01
| Show all posts
The sql statement is okay. Put it in the query analyzer and see if you can find out if you are checking it out. It should be a small problem.
Reply

Use magic Report

0

Threads

25

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-5-6 21:15:01
| Show all posts
select * from check
check is a keyword.
Plus [check]
Char type does not need to modify '"+ TextBox1.Text +"'
Reply

Use magic Report

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-5-7 22:45:01
| Show all posts
Changed to [check], or the original error, depressed. I also just found that check is a keyword =. =

Hint: Line 1: There is a syntax error near '='.
Explanation: An unhandled exception occurred during the execution of the current web request. Please check the stack trace information for details about the error and the source of the error in the code.

Exception details: System.Data.SqlClient.SqlException: Line 1: There is a syntax error near '='.

Source error:


Line 26: cmd.CommandText = "select * from [check] where tax ID = '" + TextBox1.Text + "'";
Line 27:
Line 28: SqlDataReader dr = cmd.ExecuteReader (); // red font
Line 29: if (dr.Read ())
Line 30: {
Reply

Use magic Report

0

Threads

25

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-5-9 10:15:01
| Show all posts
[Tax Number] = '"+ TextBox1.Text.Trim () +"'
Reply

Use magic Report

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-5-11 00:00:01
| Show all posts
It still doesn't work, is it because the database is not connected?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list