小弟求哥哥姐姐们帮忙指点下!~~ 如何在用鼠标在datagrid中选中一行记录,之后点确定按钮添加到数据库的一个表中??实现双击也可以,最好有个例子,谢了先~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有什么难度吗?选中一行后,组织sql语句,添加到数据库中...不知道是不是我误解了楼主的意思.. for example:SqlConnection con=new SqlConnection("server=.;database=student;uid=sa;pwd=0421");SqlCommand cmd=new SqlCommand("insert into studentDetails values(@Sno,@Sname)",con);cmd.Parameters.AddWithValue("@Sno",this.DataGrid1[CurrentRowIndex][0].ToString());cmd.Parameters.AddWithValue("@Sname",this.DataGrid1[CurrentRowIndex][1].ToString());con.Open();cmd.ExecuteNonQuery();con.Close(); TO:小弟是新手,再弱智的问一下,不知道如何用鼠标选后取出这条记录??也就是当前的记录..通过CurrentRowIndex来得到当前行的索引... private void dataGrid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e){ DataGrid.HitTestInfo hit = this.dataGrid.HitTest(e.X,e.Y) ; if(hit != null && hit.Type == DataGrid.HitTestType.Cell) { if(e.Button==System.Windows.Forms.MouseButtons.Left) { if(e.Clicks==2) { DataRowView row = this.m_DataSet.Tables[0].DefaultView[this.dataGrid.CurrentRowIndex] ; } } } } 如何刷新另一个窗体的datagridview 如何实现用软件读取网页上的信息 C# treeview获取选中节点的值 程序调试的时候运行正常,发布安装以后就不行了 webbrower自动登录 200分求拆分字符方法 c#如何实现录歌的效果啊,求大神们给点思路啊 关于WMS9多媒体插件SDK的问题 组件设计中异常应该怎么处理阿? 向指定窗口发送消息请教 关于Windows服务的路径的问题 如何实时的禁用起用工具栏按钮
SqlCommand cmd=new SqlCommand("insert into studentDetails values(@Sno,@Sname)",con);
cmd.Parameters.AddWithValue("@Sno",this.DataGrid1[CurrentRowIndex][0].ToString());
cmd.Parameters.AddWithValue("@Sname",this.DataGrid1[CurrentRowIndex][1].ToString());
con.Open();
cmd.ExecuteNonQuery();
con.Close();
{
DataGrid.HitTestInfo hit = this.dataGrid.HitTest(e.X,e.Y) ; if(hit != null && hit.Type == DataGrid.HitTestType.Cell)
{
if(e.Button==System.Windows.Forms.MouseButtons.Left)
{
if(e.Clicks==2)
{
DataRowView row = this.m_DataSet.Tables[0].DefaultView[this.dataGrid.CurrentRowIndex] ;
}
}
}
}