using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.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;data source= ./SQL2014;initial catalog=XK");
SqlCommand cmd = new SqlCommand(@"SELECT S.StuNo,StuName,WillOrder,C.* FROM StuCou SC,Student S,Course C WHERE SC.StuNo=S.StuNo AND sc.CouNo=C.CouNo AND StuName LIKE @StuName ORDER BY WillOrder", cn);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
cn.Open();
DataSet ds = new DataSet();
da.SelectCommand.Parameters.Add("StuName", SqlDbType.NVarChar).Value = "%" + txtStuName.Text + "%";
da.Fill(ds);
cn.Close();
gvXK.DataSource = ds.Tables[0];
gvXK.DataBind();
}
}
uj5u.com熱心網友回復:
1.檢查sqlcommand決議后的SQL是否正確2.Parameters中的值【StuName】debug看一下,是不是例外了
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/31271.html
標籤:C#
上一篇:C#讀取url,回傳json格式的資料(url需要賬號密碼)
下一篇:多個DevExpress.xpf.Grid.GridControl控制元件如何匯出成excel檔案中的多sheet頁?
