怎么样从gridview中获取一列数据的值?再怎么把获得的数据插入到另一个表中?没分了,还望各位大哥帮帮忙!!谢谢

问题描述

单击gridview控件外部的一个按钮,怎么获取gridview中的一列数据?获得的数据怎么插入到另一个表中,比如说那个表名是a

解决方案

解决方案二:
FindControl获取RowIndex,再cells[i].text
解决方案三:
你根据ID查询出来值,然后再把值添加到a表这样就可以了吧!
解决方案四:
DataTabledt=newDataTable();dt.Columns.Add("col1");foreach(GridViewRowgvrinGridView1.Rows){DataRowdr=dt.NewRow();dr["col1"]=gvr.Cells[列].Text;}dt.AcceptChanges();
解决方案五:
代码1:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;///<summary>///Util的摘要说明///</summary>publicclassDALUtil{publicstaticSqlConnectionGetConnection(){stringsqlconn="server=.;database=pubs;uid=sa;pwd=";try{SqlConnectionconnection=newSqlConnection(sqlconn);connection.Open();returnconnection;}catch(SqlExceptionsqlException){throwsqlException;}}}

代码2usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;usingMicrosoft.ApplicationBlocks.Data;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){bind();}}privatevoidbind(){stringSql="select*fromstu";DataSetds=newDataSet();using(SqlConnectionconn=DALUtil.GetConnection()){ds=SqlHelper.ExecuteDataset(conn,CommandType.Text,Sql);}this.GridView1.DataSource=ds.Tables[0].DefaultView;this.GridView1.DataBind();}publicstaticDataSetGetstuInfoById(intid){stringSql="select*fromstuwhereid=@id";SqlParameter[]arParms=newSqlParameter[1];arParms[0]=newSqlParameter("@id",SqlDbType.Int);arParms[0].Value=id;DataSetds=newDataSet();using(SqlConnectionconn=DALUtil.GetConnection()){ds=SqlHelper.ExecuteDataset(conn,CommandType.Text,Sql,arParms);returnds;}}protectedvoidGridView1_RowCommand(objectsender,GridViewCommandEventArgse){if(e.CommandName=="insert"){intindex=Convert.ToInt32(e.CommandArgument);DataKeykey=this.GridView1.DataKeys[index];intid=Convert.ToInt32(key.Value.ToString());DataSetds=newDataSet();ds=GetstuInfoById(id);strings=ds.Tables[0].Rows[0]["id"].ToString();stringname=ds.Tables[0].Rows[0]["name"].ToString();stringold=ds.Tables[0].Rows[0]["old"].ToString();stringc=ds.Tables[0].Rows[0]["class"].ToString();stringSql="insertintoStudent(id,name,old,class)values('"+s+"','"+name+"','"+old+"','"+c+"')";intRow=0;using(SqlConnectionconn=DALUtil.GetConnection()){SqlCommandcomm=newSqlCommand(Sql,conn);Row=comm.ExecuteNonQuery();}if(Row>0){Label1.Text="插入成功";}}}}

解决方案六:
这样就能实现你说的功能
解决方案七:
引用3楼teerhu的回复:

DataTabledt=newDataTable();dt.Columns.Add("col1");foreach(GridViewRowgvrinGridView1.Rows){DataRowdr=dt.NewRow();dr["col1"]=gvr.Cells[列].Text;}dt.AcceptChanges();

我想要插入的是已经存在的表,不是建个新表dt!怎么做?
解决方案八:
还没弄好呀,上面说得很清楚了
解决方案九:
没有啊,上面两个大哥的代码应该用哪个?我的gridview不是用代码绑定的?

时间: 2024-08-03 11:27:50

怎么样从gridview中获取一列数据的值?再怎么把获得的数据插入到另一个表中?没分了,还望各位大哥帮帮忙!!谢谢的相关文章

怎么样从gridview中获取一列数据的值?没分了,还望各位大哥帮帮忙!!谢谢

问题描述 单击gridview控件外部的一个按钮,怎么获取gridview中的一列数据? 解决方案 解决方案二:用循环啊foreach(GridViewRowmyrowinGridView1.Rows){stringlie=myrow.Cells[0].Text;}解决方案三:引用楼主wolf_268的帖子: 单击gridview控件外部的一个按钮,怎么获取gridview中的一列数据? 楼上的大哥说的yes!!!!!!!!解决方案四:帮顶!解决方案五:问一下,下边的"GridViewRow&q

sql-oracle怎么实现把一个表的数据插入到另一个表中

问题描述 oracle怎么实现把一个表的数据插入到另一个表中 oracle数据库中有两个表A.B,表的结构不一样.A表比B表多两个字段,然后我需要把B表的数据插入到A表中,但同时也需要插入A表中多的两个字段,请问这个SQL语句应该怎么写呀? 大神们请指教,,谢谢! 解决方案 insert into A(字段1,字段2,多出的字段1,多出的字段2) select 字段1,字段2,'多出的字段值1','多出的字段值2' from B

sql-oracle怎么把一个表的数据插入到另一个表中

问题描述 oracle怎么把一个表的数据插入到另一个表中 oracle数据库中有两个表A.B,表的结构不一样.A表比B表多两个字段,然后我需要把B表的数据插入到A表中,但同时也需要插入A表中多的两个字段,请问这个SQL语句应该怎么写呀? 大神们请指教,,谢谢! 解决方案 insert into a select bb.第一个字段,...bb.最后一个字段,' ',' ' from b bb; 字段要和a表的字段对应 a表中b 表没有的字段插入空值,这个位置要和你a表位置对应不一定在我写的最后 ,

sql server-本人菜鸟,求教如何把一个表的字段插入到另外一个表中

问题描述 本人菜鸟,求教如何把一个表的字段插入到另外一个表中 已知表usis.TExamination a hisbase.tpatientinfo T 2个表中都有上万条数据,有相关的,有不相关的.现在2张表通过字段关联 a.fzyh = T.fkey现在我要通过关联,把 t表中的t.flsh 插入到a.ftyzyh中语句该怎么写啊? 我自己写了条. UPDATE usis.TExamination a SET A.FTYZYH=(SELECT flsh FROM hisbase.tpatie

mysql 如何把查询到的结果插入到另一个表中

问题描述 mysql 如何把查询到的结果插入到另一个表中 首先我们在goods表中查询SELECT goods_id FROM ecs_goods WHERE goods_name = '23423423' LIMIT 1查询goods_name对应的goods_id的值然后把查询到的goods_id的值作为参数,INSERT INTO ecs_comment (comment_id comment_type id_value email user_name content comment_ra

代码实现从某个表中查询数据插入到另一个表中

前提条件&产生问题原因: 1.由于数据量比较大,又没有使用hadoop等方式处理数据.所以使用分表的形式.分表的看另一篇文章. 2.然后,需求变了,卧槽---需求又变了!!!不用分表了,需要把所有的分表数据,插入到一张表中.当然,这所有表的字段要求一致. ///稍等,待会再写,先写一篇,如果不用分布式,处理大量数据的问题. //回来了写完了, package com.tujia.ecd.table; import java.sql.ResultSet; import java.sql.SQLEx

MySql中把一个表的数据插入到另一个表中的实现代码_Mysql

小编今天在写一个 将一个数据库的表数据 导入到 另一个数据库的表的时候 我是这么写的 复制代码 代码如下: <?php header("Content-type:text/html;charset=utf-8"); $conn = mysql_connect("localhost","root","");mysql_select_db('nnd',$conn);mysql_select_db('ahjk',$conn);

单击列按钮 如何将该按钮此行的数据插入到另一个表中去

问题描述 代码如下:privatevoiddataGridView1_CellContentClick_1(objectsender,DataGridViewCellEventArgse){if(dataGridView1.Columns[e.ColumnIndex].Name=="Button"){}} 解决方案 解决方案二:能拿到行列的index就能拿到该行所有数据解决方案三:用e.RowIndex把该行数据取出来,再插入另外一个表呗.解决方案四:引用1楼xdashewan的回复:

sql将一个表中的数据插入到另一个表中的方法_MsSql

列名不一定要相同,只要你在HH中列出要插入列的列表跟select from mm表中的选择的列的列表一一对应就可以了,当然两边的数据类型应该是兼容的. insert into hh (fielda,fieldb,fieldc) select fieldx,fieldy,fieldz from mm 复制代码 代码如下: ---更新计量点中不存在的数据,将台帐中的信息转移到计量点中 insert into MetricPoints (MeterID,MetricPointName,[Descrip