Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Cách chọn 1 dòng của datagirdview load xuống SQL bằng Linq

8 năm trước 712 lượt xem 7 bình luận 8 năm trước
  • Mình làm như vậy đó......CÁi event toolStripButton1_Click là mình tạo 1 toolStripButton1 trong bindingdavigator .... Nhưng nó lỗi (SQLException was unhandled) . Mọi người giúp mình với

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
K9 SuperAdmin, KquizAdmin, KquizAuthor đã bình luận 8 năm trước

yay. ghi cái dòng dưới là hiểu nghĩa ngay. Vấn đề của bạn đã được fix bằng cách nào. Post lên và chọn nó làm đáp án đúng để sau này mọi người biết mà fix nữa nè

thienlongpha đã bình luận 8 năm trước

Mình đã fit được rồi K9 ....Thanks K9 nhiều nha 

thienlongpha đã bình luận 8 năm trước

mình hiểu ý ad rồi. Nó ghi như vậy nè :

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.Linq.dll

Additional information: String or binary data would be truncated.

The statement has been terminated.

đọc xong mình vẫn chưa tìm được lỗi gì lun

K9 SuperAdmin, KquizAdmin, KquizAuthor đã bình luận 8 năm trước

Mình đã nói. cái này bạn không nhìn code mà bắt lỗi được. làm ơn. xem kỹ cái exception nó ghi cụ thể lỗi gì. InnerException nó ghi cái gì

thienlongpha đã bình luận 8 năm trước
//Class chứa data từ sql
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace computer
{
    public class MayTinh
    {
        computerDataContext mt;
        public MayTinh()
        {
            mt = new computerDataContext();
        }
        public List<tblPhonghoc> showtree()
        {
            return mt.tblPhonghocs.Select(t => t).ToList();
        }
        public List<tblMaytinh> computershow(string maPhong)
        {
            return mt.tblMaytinhs.Where(t => t.msPhong==maPhong).ToList();
        }
        public List<tblPhonghoc> classshow()
        {
            return mt.tblPhonghocs.Select(t => t).ToList();
        }
public void addclass(tblPhonghoc e)
        {
            mt.tblPhonghocs.InsertOnSubmit(e);
            mt.SubmitChanges();
        }
}


//Form của mình
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using computer;
namespace QL_MayTinh
{
    
    public partial class Form2 : Form
    {
        computerDataContext cp;
        private MayTinh mt;
        private tblPhonghoc ph;
        
        public Form2(Form1 _f1)
        {
            cp = new computerDataContext();
            mt = new MayTinh();
            ph = new tblPhonghoc();
            InitializeComponent();
            //lvclass.View = View.Details;       
        }

        private void Form2_Load(object sender, EventArgs e)
        {           
            BindingSource b = new BindingSource();
            b.DataSource = mt.classshow();
            dataGridView1.DataSource = b;
            bindingNavigator1.BindingSource = b;
            
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ph.msPhong=dataGridView1.SelectedRows[0].Cells[0].ToString();
            ph.tenPhong = dataGridView1.SelectedRows[0].Cells[1].ToString();
            ph.toaNha = dataGridView1.SelectedRows[0].Cells[2].ToString();
            ph.tanglau =Convert.ToInt16( dataGridView1.SelectedRows[0].Cells[3].Value);
            mt.addclass(ph);
           
        }

        
    }
}

toàn code của mình đó bạn.....bạn thêm chức năng chèn ảnh đi...để mình chụp lại lỗi.... lỗi chỉ ngay dòng mt.SubmitChanges(); nó ghi SQLException was unhandled 

Câu hỏi mới nhất