| |

VerySource

 Forgot password?
 Register
Search
View: 1660|Reply: 17

Question about triggering an event by clicking the button !!

[Copy link]

1

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-25 20:00:01
| Show all posts |Read mode
I click the button to check if this field exists in the database, how to change the code. If there is a prompt, it can't be taken. If there is no prompt, you can use this name!
Trouble enlighten me !!
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-2-15 08:45:01
| Show all posts
SqlConnection conn = null;
SqlCommand cmd = null;
DataSet ds = new DataSet ();
string strConnectionString = "Data Source = .; initial catalog = database; uid = sa; pwd = xxx";
string strSQL = "SELECT 1 from table where field = 'aa'"
try
{
conn = new SqlConnection (strConnectionString);
conn.Open ();
cmd = new SqlCommand (strSQL, conn);
if (cmd.ExecuteScalar () == null)
{
                                  //does not exist
} else
{
// Exist.
}
Ranch
Ranch
}
catch (System.Exception e)
{
this.Text1.Text = "Error" + e.Message;
}
finally
{
if (conn! = null)
conn.Dispose ();
if (cmd! = null)
cmd.Dispose ();
}
Reply

Use magic Report

1

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-2-15 11:30:01
| Show all posts
Hello, what does it mean to write in catch?
Did you try it with a text box, right, showing the wrong message?

So if I have set a button, how do I write it?
Reply

Use magic Report

5

Threads

19

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-15 12:15:01
| Show all posts
e.Message; is to automatically track errors and put them into this.Text1.Text, OK! !!
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-2-15 12:45:02
| Show all posts
The catch is to report specific error information when an exception occurs. It is also important for a real programmer to write the error message.

shenmue024is written in the Click of the button, but it is obtained through the TextBox in the field function, you can add the button event above. Not quite understand what you mean? ? ? Could it be that the field value you want to query is the value of the button? ? ? Otherwise where do you get the field values ​​from?
Reply

Use magic Report

1

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-2-15 17:15:01
| Show all posts
So I just want to add a TextBox control? Capture errors in catch?
Thank you guys.
Reply

Use magic Report

5

Threads

19

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-15 18:00:01
| Show all posts
If it is a button, then write the above code in the check event of the button:
: This.Text1.Text = "Error" + e.Message;
To:
Response.Write ("<script language = javascript> alert ('" + "Error" + e.Message; + "'); </ script>");

It's OK. . . Try
Reply

Use magic Report

5

Threads

19

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-15 18:45:01
| Show all posts
The previous "" is wrong, change it yourself
Reply

Use magic Report

1

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-2-15 20:00:01
| Show all posts
No, it seems wrong. The client statement above.
Reply

Use magic Report

1

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-2-15 20:30:01
| Show all posts
A local variable named "e" cannot be declared in this scope because it would give "e" a different meaning, and it is already used in the "parent or current" scope to indicate something else


catch (System.Exception e) is this:
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