Having









How do I use Having
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets

Line Code Ex..
255 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity),sum(Price*Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName"; 1
314 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity),sum(Price*Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID and ProductName like '" + txtProductName.Text + "%' group by product.ProductID,productname,Price,Features,Quantity having(quantity>0) order by ProductName"; 2
399 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID and ProductName like '" + txtProduct.Text + "%' group by product.ProductID,productname,Price,Features,Quantity having(quantity>0) order by ProductName"; 3
450 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName"; 4
410 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID and ProductName like '" + txtProduct.Text + "%' group by product.ProductID,productname,Price,Features,Quantity having(quantity>0) order by ProductName"; 5
461 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName"; 6
400 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID and ProductName like '" + txtProduct.Text + "%' group by product.ProductID,productname,Price,Features,Quantity having(quantity>0) order by ProductName"; 7
451 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName"; 8

File name: frmMainMenu.cs Copy
249         public void GetData()
250         {
251             try
252             {
253                 con = new SqlConnection(cs.DBConn);
254                 con.Open();
255                 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity),sum(Price*Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName";
256                 cmd = new SqlCommand(sql, con);
257                 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
258                 dataGridView1.Rows.Clear();
259                 while (rdr.Read() == true)
260                 {
261                     dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4], rdr[5]);
262                 }
263                 foreach (DataGridViewRow r in this.dataGridView1.Rows)
264                 {
265                     if (Convert.ToInt32(r.Cells[4].Value) < 10)
266                     {
267                         r.DefaultCellStyle.BackColor = Color.Red;
268                     }
269                 }
270                 con.Close();
271             }
272             catch (Exception ex)
273             {
274                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
275             }
276         }
File name: frmMainMenu.cs Copy
309         private void textBox1_TextChanged(object sender, EventArgs e)
310         {
311             try{
312             con = new SqlConnection(cs.DBConn);
313                 con.Open();
314                 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity),sum(Price*Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID and ProductName like '" + txtProductName.Text + "%' group by product.ProductID,productname,Price,Features,Quantity having(quantity>0) order by ProductName";
315                 cmd = new SqlCommand(sql, con);
316                 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
317                 dataGridView1.Rows.Clear();
318                 while (rdr.Read() == true)
319                 {
320                     dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4], rdr[5]);
321                 }
322                 foreach (DataGridViewRow r in this.dataGridView1.Rows)
323                 {
324                 if (Convert.ToInt32(r.Cells[4].Value) < 10)
325                 {
326                     r.DefaultCellStyle.BackColor = Color.Red;
327                 }
328             }
329                 con.Close();
330             }
331             catch (Exception ex)
332             {
333                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
334             }
335         }
File name: frmOrder.cs Copy
393         private void textBox1_TextChanged(object sender, EventArgs e)
394         {
395             try
396             {
397                 con = new SqlConnection(cs.DBConn);
398                 con.Open();
399                 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID and ProductName like '" + txtProduct.Text + "%' group by product.ProductID,productname,Price,Features,Quantity having(quantity>0) order by ProductName";
400                 cmd = new SqlCommand(sql, con);
401                 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
402                 dataGridView1.Rows.Clear();
403                 while (rdr.Read() == true)
404                 {
405                     dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4]);
406                 }
407                 con.Close();
408             }
409             catch (Exception ex)
410             {
411                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
412             }
413         }
File name: frmOrder.cs Copy
444         public void GetData()
445         {
446             try
447             {
448                 con = new SqlConnection(cs.DBConn);
449                 con.Open();
450                 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName";
451                 cmd = new SqlCommand(sql, con);
452                 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
453                 dataGridView1.Rows.Clear();
454                 while (rdr.Read() == true)
455                 {
456                     dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3],rdr[4]);
457                 }
458                 con.Close();
459             }
460             catch (Exception ex)
461             {
462                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
463             }
464         }
File name: frmPlaceOrders.cs Copy
404         private void textBox1_TextChanged(object sender, EventArgs e)
405         {
406             try
407             {
408                 con = new SqlConnection(cs.DBConn);
409                 con.Open();
410                 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID and ProductName like '" + txtProduct.Text + "%' group by product.ProductID,productname,Price,Features,Quantity having(quantity>0) order by ProductName";
411                 cmd = new SqlCommand(sql, con);
412                 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
413                 dataGridView1.Rows.Clear();
414                 while (rdr.Read() == true)
415                 {
416                     dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4]);
417                 }
418                 con.Close();
419             }
420             catch (Exception ex)
421             {
422                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
423             }
424         }
File name: frmPlaceOrders.cs Copy
455         public void GetData()
456         {
457             try
458             {
459                 con = new SqlConnection(cs.DBConn);
460                 con.Open();
461                 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName";
462                 cmd = new SqlCommand(sql, con);
463                 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
464                 dataGridView1.Rows.Clear();
465                 while (rdr.Read() == true)
466                 {
467                     dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3],rdr[4]);
468                 }
469                 con.Close();
470             }
471             catch (Exception ex)
472             {
473                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
474             }
475         }
File name: frmSales.cs Copy
394         private void textBox1_TextChanged(object sender, EventArgs e)
395         {
396             try
397             {
398                 con = new SqlConnection(cs.DBConn);
399                 con.Open();
400                 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID and ProductName like '" + txtProduct.Text + "%' group by product.ProductID,productname,Price,Features,Quantity having(quantity>0) order by ProductName";
401                 cmd = new SqlCommand(sql, con);
402                 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
403                 dataGridView1.Rows.Clear();
404                 while (rdr.Read() == true)
405                 {
406                     dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4]);
407                 }
408                 con.Close();
409             }
410             catch (Exception ex)
411             {
412                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
413             }
414         }
File name: frmSales.cs Copy
445         public void GetData()
446         {
447             try
448             {
449                 con = new SqlConnection(cs.DBConn);
450                 con.Open();
451                 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName";
452                 cmd = new SqlCommand(sql, con);
453                 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
454                 dataGridView1.Rows.Clear();
455                 while (rdr.Read() == true)
456                 {
457                     dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3],rdr[4]);
458                 }
459                 con.Close();
460             }
461             catch (Exception ex)
462             {
463                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
464             }
465         }

Having 147 lượt xem

Gõ tìm kiếm nhanh...