我通过鼠标单击选择记录不接受数据网格视图中的更新记录时遇到问题 [英] I have a problem when select record by mouse click didn't accept update record in datagrid view

查看:67
本文介绍了我通过鼠标单击选择记录不接受数据网格视图中的更新记录时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hii,每个人



我有一个问题,当鼠标点击选择记录时不接受(更新,删除)数据网格视图中的记录

但必须通过按钮选择记录(第一条记录,最后一条记录,下一条,上一条记录),而不是通过鼠标点击。

这是代码更新按钮

  int  x; 

da.UpdateCommand = new SqlCommand( update tblcontacts set firstname = @ firstname,lastname = @ lastname where id = @ id,cs);
da.UpdateCommand.Parameters.Add( @ firstname,SqlDbType.VarChar)。 Value = textBox1.Text;
da.UpdateCommand.Parameters.Add( @ lastname,SqlDbType.VarChar)。 Value = textBox2.Text;
da.UpdateCommand.Parameters.Add( @ id,SqlDbType.BigInt)。值= ds.Tables [ 0 ]。行[tblnamesbs.Position] [ 0 ];

cs.Open();
x = da.UpdateCommand.ExecuteNonQuery();
cs.Close();

if (x > = 1
MessageBox.Show( 记录已更新);



此代码显示数据

 da.SelectCommand =  new  SqlCommand(  select * from tblcontacts,cs); 
ds.Clear();
da.Fill(ds);

dt = ds.Tables [ 0 ];
dataGridView1.DataSource = ds.Tables [ 0 ];
// DataTable dt = new DataTable();

// dt.Columns.Add(firstname,typeof(string));
// dt.Columns.Add(lastname,typeof(string));

tblnamesbs.DataSource = dt;
this .textBox1.DataBindings.Clear();
this .textBox1.DataBindings.Add( 文字 .tblnamesbs, firstname true );
this .textBox2.DataBindings.Clear();
this .textBox2.DataBindings.Add( 文字 .tblnamesbs, lastname true );
记录();



此代码转到第一条记录:

 tblnamesbs.DataSource = DT; 
tblnamesbs.MoveFirst();
dgupdate();
records();

解决方案

你说'通过鼠标点击选择记录来更新它,不工作',但是,我没有看到你编写任何代码来实现这一点。您发布的所有代码都与此无关。您需要处理HTML中的单击,以便触发您发布的所有代码。你在哪做什么?





这里 [ ^ ]是关于你想要做什么的文章。请用代码解释为什么你认为点击一行应该允许在你的情况下编辑,如果你仍然卡住了。



我刚才意识到这篇文章是WPF,然后意识到你实际上并没有告诉我们你在使用什么。您没有使用C#3.0和C#4.0,但无论哪种方式,目前尚不清楚您是否使用ASP.NET,MVC,winforms,WPF或什么?


实用程序记录鼠标单击记录键盘输入。它也可以记录测试用例 [ ^ ]


hii,everyone

I have a problem when select record by mouse click didn't accept (update,delete) record in datagrid view
but must select record by buttons i make (first record,last record,next,previous) not by mouse click .
this is code update button

int x;

da.UpdateCommand = new SqlCommand("update tblcontacts set firstname=@firstname,lastname=@lastname where id=@id ", cs);
da.UpdateCommand.Parameters.Add("@firstname", SqlDbType.VarChar).Value = textBox1.Text;
da.UpdateCommand.Parameters.Add("@lastname", SqlDbType.VarChar).Value = textBox2.Text;
da.UpdateCommand.Parameters.Add("@id", SqlDbType.BigInt).Value = ds.Tables[0].Rows[tblnamesbs.Position][0];

cs.Open();
x= da.UpdateCommand.ExecuteNonQuery();
cs.Close();

if (x >= 1)
    MessageBox.Show("Record(s) has been updated");


this code display data

da.SelectCommand = new SqlCommand("select * from tblcontacts ", cs);
ds.Clear();
da.Fill(ds);

dt=ds.Tables[0];
dataGridView1.DataSource = ds.Tables[0];
//DataTable dt = new DataTable();

//dt.Columns.Add("firstname", typeof(string));
//dt.Columns.Add("lastname", typeof(string));

tblnamesbs.DataSource = dt;
this.textBox1.DataBindings.Clear();
this.textBox1.DataBindings.Add("Text", this.tblnamesbs, "firstname", true);
this.textBox2.DataBindings.Clear();
this.textBox2.DataBindings.Add("Text", this.tblnamesbs, "lastname", true);
records();


this code go to first record :

tblnamesbs.DataSource = dt;
            tblnamesbs.MoveFirst();
            dgupdate();
            records();

解决方案

You say 'select record by mouse click to update it ,not working', but, I don't see anywhere that you have written code to make that happen. None of the code you've posted has anything to do with that. You need to handle a click in your HTML, in order to trigger all the code you've posted. Where are you doing that ?


Here[^] is an article on what you're trying to do. Please explain, with code, why you think that clicking on a row should allow editing in your case, if you're still stuck.

I just realised this article is WPF, THEN realised you don't actually tell us what you're using. You are not using C# 3.0 AND C# 4.0, but either way, it's not clear if you're using ASP.NET, MVC, winforms, WPF, or what ?


utility to record mouse click and record keyboard inputs. Also it can record Test Cases[^]


这篇关于我通过鼠标单击选择记录不接受数据网格视图中的更新记录时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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