自动DataGridView AddWithValue SqlDataAdapter [英] Automatic DataGridView AddWithValue SqlDataAdapter

查看:69
本文介绍了自动DataGridView AddWithValue SqlDataAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有这样的代码:

自动更新datagridview中的更改

我需要它:

由于我在datagridview中没有名为akce的列,我需要它自动插入每个新行值,从zakce.Text到sql表中的akce列。



有没有办法做到这一点?我尝试了现在注释的代码,但它创建了新行,而不是将其添加到datagridview中的新行。



Hello guys,
I have this code which does:
Automatically updates changes in datagridview
I need it to:
As I don't have column named "akce" in datagridview I need it to automatically insert to every new row value from zakce.Text to column "akce" in sql table.

Is there any way to do that? I tried the code which is now commented but it creates new row instead adding this to new row in datagridview.

da = new SqlDataAdapter("select * from zajsluz WHERE akce="+zakce.Text, spojeni);
                //SqlCommand a = new SqlCommand("INSERT INTO zajsluz(akce)values(@akce)");
                //a.Parameters.AddWithValue("@akce", zakce.Text);
                sqlCommandBuilder = new SqlCommandBuilder(da);
                dt = new DataTable();
                da.Fill(dt);
                dtg_sluzby.DataSource = dt;



这是我在更新btton上的代码:


and this is my code on update btton:

public void btn_uloz_sl_Click(object sender, EventArgs e)
        {
            try
            {
                da.Update(dt);
                MessageBox.Show("Služby byly editovány!");
            }
            catch (Exception se)
            {
                MessageBox.Show(se.Message);
            }
 
        }

推荐答案

看看这里:使用默认值自动填充datagridview中的列 [ ^ ]。在那里你会找到一个aswer;)
Have a look here: Automatically fill column in datagridview with default value[^]. There you'll find an aswer ;)


这篇关于自动DataGridView AddWithValue SqlDataAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆