Home > Net >  The user code untreated System. The Data. SqlClient. SqlException Class=ErrorCode=20-2146232060
The user code untreated System. The Data. SqlClient. SqlException Class=ErrorCode=20-2146232060

Time:11-19

using System;
using System.Collections.Generic;
using System.Linq;
Using System. The Web;
Using System. Web. UI.
Using System. Web. UI. WebControls;
Using System. The Data;
Using System. The Data. SqlClient.

Public partial class _Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{

}

Protected void btnLoad_Click (object sender, EventArgs e)
{
SqlConnection cn=new SqlConnection (" integrated security=TRUE; The data source=./SQL2014; Initial catalog=XK ");
SqlCommand CMD=new SqlCommand (@ "SELECT S.S tuNo, StuName, WillOrder, c. * FROM StuCou SC, the Student S Course C WHERE SC. StuNo=S.S tuNo AND SC. CouNo=Arthur c. ouNo AND StuName LIKE @ StuName ORDER BY WillOrder", cn);
SqlDataAdapter da=new SqlDataAdapter ();
Da. SelectCommand=CMD;
Cn. The Open ();
The DataSet ds=new DataSet ();
Da. SelectCommand. The Parameters. The Add (" StuName ", SqlDbType. NVarChar). The Value="https://bbs.csdn.net/topics/%" + txtStuName. Text + "%";
Da. The Fill (ds);
Cn. The Close ();
GvXK. The DataSource=ds. Tables [0];
GvXK. DataBind ();


}
}

CodePudding user response:

1. Check the sqlcommand parsed SQL is correct
2. The values of the Parameters StuName debug to look at, it is abnormal
  •  Tags:  
  • C#
  • Related