自动DataGridView更新AddWithValue [英] Automatic DataGridView update AddWithValue

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

问题描述

大家好,

我有这样的代码:

自动更新datagridview中的更改

我需要它:

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



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

 da =  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上的代码:



  public   void  btn_uloz_sl_Click( object  sender,EventArgs e)
{
try
{
da.Update(dt);
MessageBox.Show( Službybylyeditovány!);
}
catch (例外se)
{
MessageBox.Show(se.Message);
}

}







谢谢提前

解决方案

在 > sql table  整数或文本

如果整数
select * from zajsluz WHERE akce = + convert.toint16(zakce.text);

if it text
select * from zajsluz WHERE akce =' + zakce.text + '< /跨度>;
< / pre >


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;



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);
         }

     }




Thanks in advance

解决方案

did akce column in sql table is integer or text

if it integer 
"select * from zajsluz WHERE akce= "+convert.toint16(zakce.text);

if it text
"select * from zajsluz WHERE akce= '"+zakce.text +"'";
</pre>


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

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