คับ มันขึ้น Error ว่า : Must declare the scalar variable "@customerid".
นี่เป็นโค๊ตส่วนคิวรี่คับ :
Code (C#)
private void button1_Click(object sender, EventArgs e)
{
Item tempitem = (Item)lb1.SelectedItem;
//string cid = tempitem.Value.ToString();
bill drd = new bill();
string cs = @"Data Source=MNIKE\SQLEXPRESS;Initial Catalog=Databasefor21;Persist Security Info=True;User ID=sa;Password=1234";
SqlConnection cn = new SqlConnection(cs);
SqlDataAdapter da = new SqlDataAdapter("SELECT a.BillID,c.ProductName,b.SealNumber,c.Quantity,c.Fee,d.CustomerName FROM (([Bills] a Join [Billss] b On a.BillID=b.BillID) Join [Products] c On b.SealNumber=c.SealNumber) Join [Customers] d On a.CustomerID=d.CustomerID Where a.CustomerID=@customerid", cn);
cmd.Parameters.AddWithValue("@customerid",tempitem.Value.ToString());
da.Fill(drd, drd.Tables[0].TableName);
ReportDataSource rds = new ReportDataSource("Bills", drd.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
}
นี่เป็นโค๊ตแสดงComboboxคับ :
Code (C#)
private void combonamecus()
{
SqlConnection con = new SqlConnection(@"Data Source=MNIKE\SQLEXPRESS;Initial Catalog=Databasefor21;Persist Security Info=True;User ID=sa;Password=1234");
con.Open();
cmd = new SqlCommand("Select * From Customers");
cmd.Connection = con;
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
lb1.Items.Add(new Item(reader["CustomerName"].ToString(), Int32.Parse(reader["CustomerID"].ToString())));
}
reader.Close();
}
ลิ้งรูปภาพประกอบ
Tag : .NET, Ms SQL Server 2008, Win (Windows App), C#
private void button1_Click(object sender, EventArgs e)
{
Item tempitem = (Item)lb1.SelectedItem;
//string cid = tempitem.Value.ToString();
bill drd = new bill();
string cs = @"Data Source=MNIKE\SQLEXPRESS;Initial Catalog=Databasefor21;Persist Security Info=True;User ID=sa;Password=1234";
SqlConnection cn = new SqlConnection(cs);
SqlDataAdapter da = new SqlDataAdapter("SELECT a.BillID,c.ProductName,b.SealNumber,c.Quantity,c.Fee,d.CustomerName FROM (([Bills] a Join [Billss] b On a.BillID=b.BillID) Join [Products] c On b.SealNumber=c.SealNumber) Join [Customers] d On a.CustomerID=d.CustomerID Where a.CustomerID=@customerid", cn);
cmd.Parameters.AddWithValue("@customerid",tempitem.Value.ToString());
da.Fill(drd, drd.Tables[0].TableName);
ReportDataSource rds = new ReportDataSource("Bills", drd.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
}
ทำไมมันมาดโดด ๆ ครับ
ลองดูตัวอย่างนี้ครับ
Code (C#)
//*** DataTable ***'
SqlDataAdapter dtAdapter = default(SqlDataAdapter);
DataTable dt = new DataTable();
strSQL = "SELECT * FROM files WHERE FilesID = @sFilesID ";
dtAdapter = new SqlDataAdapter(strSQL, objConn);
objCmd = dtAdapter.SelectCommand;
objCmd.Parameters.Add("@sFilesID", SqlDbType.Int).Value = Request.QueryString["FilesID"].ToString();
dtAdapter.Fill(dt);