|  | 
	                
  
    |  |  
    | 
        
        ผมทำการเขียน CODE Delete เขีัยนไปลบได้ไม่error แต่มันไม่ลบออกจากฐานข้อมูลครับทำไงดี     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | Code (C#) 
 private void cmdDelete_Click_1(object sender, EventArgs e)
        {
            /* ptable.Deletepr(txtidpro.Text,txtNamepro.Text,decimal.Parse(txtpro.Text),txtIDCat.Text, textBox1.Text, decimal.Parse(textBox4.Text));
                MydatabaseDataSet.ProductDataTable ta = (MydatabaseDataSet.ProductDataTable)ptable.GetProductById(txtidpro.Text);
                dgvProduct.DataSource = ta;
                ShowData();
                MessageBox.Show("คุณลบการสั่งซื้อสินค้าเรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ClearAllData();
                 /*/
            try
            {
                sb = new StringBuilder();
                sb.Append("DELETE FROM Product");
                sb.Append(" WHERE รหัสสินค้า=@รหัสสินค้า");
                sb.Append(" AND ชื่อสินค้า=@ชื่อสินค้า");
                sb.Append(" AND ราคาทุน=@ราคาทุน");
                sb.Append(" AND ราคาขาย=@ราคาขาย");
                sb.Append(" AND รหัสประเภทสินค้า=@รหัสประเภทสินค้า");
                sb.Append(" AND ชื่อประเภทสินค้า=@ชื่อประเภทสินค้า");
                string sqlDelete;
                sqlDelete = sb.ToString();
                if (MessageBox.Show("คุณต้องการลบข้อมูลสินค้า ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    com.CommandText = sqlDelete;
                    com.CommandType = CommandType.Text;
                    com.Connection = Conn;
                    com.Parameters.Clear();
                    com.Parameters.Add("@รหัสสินค้า", SqlDbType.NVarChar).Value = txtidpro.Text.Trim();
                    com.Parameters.Add("@ชื่อสินค้า", SqlDbType.NVarChar).Value = txtNamepro.Text.Trim();
                    com.Parameters.Add("@ราคาทุน", SqlDbType.Money).Value = textBox4.Text.Trim();
                    com.Parameters.Add("@ราคาขาย", SqlDbType.Money).Value = txtpro.Text.Trim();
                    com.Parameters.Add("@รหัสประเภทสินค้า", SqlDbType.NChar).Value = txtIDCat.Text.Trim();
                    com.Parameters.Add("@ชื่อประเภทสินค้า", SqlDbType.NChar).Value = textBox1.Text.Trim();
                    com.ExecuteNonQuery();
                    MessageBox.Show("คุณลบข้อมูลเรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearAllData();
                    ShowData();
                }
                 
            }
            catch (Exception ex)
            {
                MessageBox.Show("ไม่สามารถลบข้อมูลได้ เนื่องจาก " + ex.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 
 
 Tag : C#
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2012-08-22 08:12:21 | By :
                          texbit007 | View :
                          1119 | Reply :
                          8 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ทำไมไม่ where เฉพาะรหัสสินค้าล่ะคับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-08-22 08:47:51 | By :
                            ichiko |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ขอบคุนครับ  ได้แล้วครับ>>>> 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-08-22 08:59:46 | By :
                            texbit007 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | พี่ครับ  ผมทำ Code update  มัน Error string or binary data would be truncated. the statement has been terminated 
 ผมลองไปปรับ ฟิลด์ แล้วก็เหมือนเดิม  ขอรายละเอียดวิธีแก้ไขหน่อยครับ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-08-22 09:17:23 | By :
                            texbit007 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | พี่ครับ  ปรับหมดแล้วน่ะ   ในฐานข้อมูลน่ะพี่ยังไม่ได้เหมือนเดิมขอรายละเอียดกว่านี้ด้วยครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-08-23 16:38:44 | By :
                            texbit007 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ได้แล้วครับขอบคุนครับ>>>// 
 
 พี่การทำ  Report  ล่ะครับ  ผมทำแล้ว  ขอมูลมันไม่ขึ้นครับ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-08-23 17:03:28 | By :
                            texbit007 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | การทำรายงาน  >>>> มัน Error ครับทำไงครับ 
 
 SqlConnection Conn = new SqlConnection();
 SqlCommand com = new SqlCommand();
 SqlDataAdapter sd = new SqlDataAdapter();
 
 DataSet ds = new DataSet();
 DataTable dt = null;
 string strConnString = null;
 string strSQL = null;
 
 strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
 strSQL = "SELECT * FROM Category WHERE รหัสประเภทสินค้า = '" + this.txtse.Text + "' ";
 
 Conn.ConnectionString = strConnString;
 var _with1 = com;
 _with1.Connection = Conn;
 _with1.CommandText = strSQL;
 _with1.CommandType = CommandType.Text;
 sd.SelectCommand = com;
 sd.Fill(ds, "Category");
 dt = ds.Tables[0];
 sd = null;
 Conn.Close();
 Conn = null;
 ReportDocument rpt = new ReportDocument();
 string directory = My.Application.Info.DirectoryPath;
 //Error บรรทัดนี้ครับ      rpt.Load("C:\Documents and Settings\classic\My Documents\Visual Studio        2008\Projects\NKP\NKP\Report\Ca.rpt");//มันError บรรทัดนี้ครับ
 rpt.SetDataSource(dt);
 this.CrystalReportViewer1.ReportSource = rpt;
 this.CrystalReportViewer1.Refresh();
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-09-04 09:27:03 | By :
                            texbit007 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ได้แล้วครับ>>> แล้วถ้าอยากให้ >>ข้อมูลโชว์ ทั้งหมดล่ะครับต้องเขียน code เพิ่มตรงไหนม่ายครับ 
 
 SqlConnection Conn = new SqlConnection();
 SqlCommand com = new SqlCommand();
 SqlDataAdapter sd = new SqlDataAdapter();
 
 DataSet ds = new DataSet();
 DataTable dt = null;
 string strConnString = null;
 string strSQL = null;
 
 strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
 strSQL = "SELECT * FROM Category WHERE รหัสประเภทสินค้า = '" + this.txtse.Text + "' ";
 
 Conn.ConnectionString = strConnString;
 var _with1 = com;
 _with1.Connection = Conn;
 _with1.CommandText = strSQL;
 _with1.CommandType = CommandType.Text;
 sd.SelectCommand = com;
 sd.Fill(ds, "Category");
 dt = ds.Tables[0];
 sd = null;
 Conn.Close();
 Conn = null;
 ReportDocument rpt = new ReportDocument();
 rpt.Load("C:\\Documents and Settings\\classic\\My Documents\\Visual Studio 2008\\Projects\\NKP\\NKP\\Report\\Ca.rpt");
 rpt.SetDataSource(dt);
 this.crystalReportViewer1.ReportSource = rpt;
 this.crystalReportViewer1.Refresh();
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-09-04 09:54:53 | By :
                            texbit007 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |