Home > Net >  Could you help to modify the code... Has been an error
Could you help to modify the code... Has been an error

Time:11-13

 using System; 
using System.Collections.Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using System. Windows. Forms;
Using System. The Data. SqlClient.
Using System. Data. SqlTypes;


The namespace yifeiapp1
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent ();
}

Private void label1_Click (object sender, EventArgs e)
{

}

Private void button1_Click (object sender, EventArgs e)
{
SqlConnection con=new SqlConnection (" server="+ textBox1. Text +"; The database=DSCSYS; Uid="+ textBox2. Text +"; The Pwd="+ textBox3. Text +" ");

String SQLSTR="CREATE FUNCTION [dbo] [DecodePwd]" +
"(@ user nvarchar (32), @ userPwd nvarchar (128)" +
"RETURNS nvarchar (128) +"
"AS +"
"BEGIN" +
"DECLARE @ Return NVARCHAR (128) +"
"SET @ Return=" '+ "
"DECLARE @ KeyLen INT, @ INT, I @ n1 INT, @ n2 INT" +
"DECLARE @ FStr1 CHAR (1), @ FStr2 CHAR (1), @ FStr3 CHAR (1), @ FStr4 CHAR (1)" +
"DECLARE @ fnil nvarchar (128), @ FF1 nvarchar (128)" +
"SET @ fnil='(& amp; . & amp; ! % & amp; $\ "& amp;) \ \ "", & amp;) $(% # $- $# $$\ "" +
"The SET @ FF1=! \ "# $% & amp; (a) *, +, -,/"+
"DECLARE @ n int, @ d int" +
"DECLARE @ Result nvarchar (128) +"
"SET @ I=LEN (@ user)" +
"The SET @ Result=the SUBSTRING (@ fnil, (@ I - 1) * 2 + 1, 30 - (@ I - 1) * 2)" +
"SET @ n=@ I - 1" +
"WHILE (@ n & gt;=0) + "
"BEGIN" +
"The SET @ I=(ASCII (SUBSTRING (@ user, @ the n + 1, 1)) - 32) % 16" +
"The SET @ d=(ASCII (SUBSTRING (@ user, @ the n + 1, 1)) - 32)/16 + 1" +
"SET @ Result=@ Result + CHAR (32 + @ d + 1) + the SUBSTRING (@ FF1, @ I + 1, 1)" +
"SET @ n=@ n - 1" +
"The END" +
"SET @ KeyLen=0 +"
"SET @ I=28 +"
"WHILE (@ I & gt;=1) + "
"BEGIN" +
"IF the SUBSTRING (@ userPwd, @ I, 1) & lt;> The SUBSTRING (@ Result, @ I, 1)) + "
"BEGIN" +
"SET @ KeyLen=@ I +"
"BREAK; + "
"The END" +
"The SET @ I=@ I - 1" +
"The END" +
"IF (@ KeyLen=0) RETURN" '" +
"SET @ I=@ KeyLen +"
"WHILE (@ I & gt;=1) + "
"BEGIN" +
"IF (@ I & lt;=4) + "
"BEGIN" +
"The SET @ FStr1=the SUBSTRING (@ Result, @ I, 1)" +
"The SET @ FStr3=the SUBSTRING (@ userPwd, @ I, 1)" +
"The SET @ FStr4=the SUBSTRING (@ userPwd, 32-4 + @ I, 1)" +
"The SET @ n1=ASCII (@ FStr1) ^ ASCII (@ FStr3)" +
"The SET @ n2=((ASCII (@ FStr4) - 32)/16)" +
"The SET @ Return=CHAR (16 * @ n2) + 32 + @ n1) + @ Return" +
"The SET @ FStr4=CHAR (16) (ASCII (@ FStr4) % + 32)" +
"SET @ userPwd=the SUBSTRING (@ userPwd, 1, 32-4 + @ I - 1) + @ FStr4 + SUBSTRING (@ userPwd, 32-4 + @ I + 1, 4 - @ I)" +
"The END" +
"The ELSE +"
"BEGIN" +
"The SET @ FStr1=the SUBSTRING (@ Result, @ I, 1)" +
"The SET @ FStr3=the SUBSTRING (@ userPwd, @ I, 1)" +
"The SET @ FStr4=the SUBSTRING (@ userPwd, @ I - 4, 1)" +
"The SET @ n1=ASCII (@ FStr1) ^ ASCII (@ FStr3)" +
"The SET @ n2=((ASCII (@ FStr4) - 32)/16)" +
"The SET @ Return=CHAR (16 * @ n2) + 32 + @ n1) + @ Return" +
"The SET @ FStr4=CHAR (16) (ASCII (@ FStr4) % + 32)" +
"SET @ userPwd=the SUBSTRING (@ userPwd, 1, @ I - 4-1) + @ FStr4 + SUBSTRING (@ userPwd, @ I - 4 + 1, 32 - @ I + 4)" +
"The END" +
"The SET @ I=@ I - 1" +
"The END" +
"RETURN @ RETURN +"
"The End";


SqlCommand CMD=new SqlCommand (SQLSTR, con);
CMD. Connection=con;
Cmd.Com mandText=SQLSTR;
Cmd.Com mandType=CommandType. Text;
Con. The Open ();
CMD. ExecuteNonQuery ();
Con. The Close ();



}

Private void button2_Click (object sender, EventArgs e)
{
SqlConnection con=new SqlConnection (" server="+ textBox1. Text +"; The database=DSCSYS; Uid="+ textBox2. Text +"; The Pwd="+ textBox3. Text +" ");
SqlDataAdapter da=new SqlDataAdapter (" SELECT MA001 as user name, dbo. DecodePwd (MA001 MA003) as the password from DSCMA ", con);
DataSet ds=new DataSet();
Da. The Fill (ds);

The DataTable DTB=ds. Tables [0];

DataGridView1. The DataSource=DTB;
Con. The Close ();







}

Private void Form1_Load (object sender, EventArgs e)
{

}
}
}

CodePudding user response:

To execute SQL statements, and in the condition of debugging to copy out, put in database management tools, and see if I can, this is a basic debugging skills,

CodePudding user response:

I is according to the SQL tool can execute the statement by c # to achieve, don't know what went wrong,,

CodePudding user response:

I is according to the SQL tool can execute the statement by c # to achieve, don't know what went wrong,

CodePudding user response:

Is this your patchwork of statement

CodePudding user response:

Thank you very much, upstairs seemed done,

CodePudding user response:

Why should function in the code on execution to create, should not be called for, your offer a firm one mistake this is not the function already exists! I don't how to use a function, use the stored procedurenullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related