小编Sum*_*umi的帖子

如何使用DataGridView在SQL Server中存储多个记录

我正在尝试使用C#从DataGridView向SQL Server数据库表中插入5条记录.

从我的代码中,它需要输入几个记录,但只插入数据库中的第一条记录.任何人都可以通过单击保存按钮帮助我在数据库中保存5条记录吗?

这是我的代码:

    DataSet ds = new DataSet();

    SqlConnection cs = new SqlConnection(@"Data Source=DELL-PC;Initial Catalog=Image_DB;Integrated Security=True");

    SqlDataAdapter da = new SqlDataAdapter();

    SqlCommand cmd = new SqlCommand();

    BindingSource Input = new BindingSource();
    DataView dview = new DataView();

    private void Form1_Load(object sender, EventArgs e)
    {
        //create a DataGridView Image Column
        DataGridViewImageColumn dgvImage = new DataGridViewImageColumn();
        //set a header test to DataGridView Image Column
        dgvImage.HeaderText = "Images";
        dgvImage.ImageLayout = DataGridViewImageCellLayout.Stretch;

        DataGridViewTextBoxColumn dgvId = new DataGridViewTextBoxColumn();
        dgvId.HeaderText = "ID";

        DataGridViewTextBoxColumn dgvName = new …
Run Code Online (Sandbox Code Playgroud)

c# sql-server datagridview

6
推荐指数
1
解决办法
942
查看次数

如果使用C#,如何打破if-else-

我怎么打破if-else-if .....为什么它不起作用?它只是检查所有条件而不是执行任务.以下是我的代码.我已经通过断点检查了它是否符合所有条件,为什么它在满足正确条件后不会停止.即使它没有进入if活动,它只是阅读所有条件,最后什么都不做.

private void ShowHash()
    {
        inpic = pb_selected.Image;
        Bitmap image = new Bitmap(inpic);
        byte[] imgBytes = new byte[0];
        imgBytes = (byte[])converter.ConvertTo(image, imgBytes.GetType());
        string hash = ComputeHashCode(imgBytes);
        txt_selectedText.Text = hash;
        GetHash();
    }

private void GetHash()
    {
        if (txt_sel1.Text == null && (txt_sel2.Text == null || txt_sel3.Text == null || txt_sel4.Text == null || txt_sel5.Text == null ))
        {
            txt_sel1.Text = txt_selectedText.Text;
            return;
        }

        else if (txt_sel1.Text != null && (txt_sel2.Text == null || txt_sel3.Text == null || txt_sel4.Text == null …
Run Code Online (Sandbox Code Playgroud)

c# if-statement

-2
推荐指数
1
解决办法
2011
查看次数

标签 统计

c# ×2

datagridview ×1

if-statement ×1

sql-server ×1