我的数据库里一共有两个表,一个是Pocket_book,一个是Project_book
string MyConn = "server=SQLOLEDB;Data Source=OOCO8HPY5V6TMKN;User ID=sa;Initial Catalog=Licai";
SqlConnection MyConnection = new SqlConnection(MyConn);
//-----------------select语句--------------------
SqlCommand MyCommand = new SqlCommand("select Main_ID as 编号,IO_Date as 收支日期,Type as 类型,Project as 项目,Money as 金额,Explain as 说明,Mark as 删除标记 from Pocket_book,Project_book where Pocket_book.A_ID = Project_book.A_ID and Pocket_book.B_ID = Project_book.B_ID", MyConnection);DataTable dt = new DataTable();
SqlDataAdapter SelectAdapter = new SqlDataAdapter();//定义一个数据适配器
SelectAdapter.SelectCommand = MyCommand;//定义数据适配器的操作指令
DataSet MyDataSet = new DataSet();//定义一个数据集
MyConnection.Open();//打开数据库连接
SelectAdapter.SelectCommand.ExecuteNonQuery();//执行数据库查询指令
SelectAdapter.Fill(MyDataSet, "Pocket_book");
System.Text.StringBuilder strSql = new System.Text.StringBuilder();
dgvInformation.AutoGenerateColumns = true;
dgvInformation.DataSource = MyDataSet.Tables[0];
DataTable dt = MyDataSet.Tables[0];在datagridview上显示,双击某一行进行修改,将这一行的值传给下一个窗体,在下一个窗体用几个textbox
控件显示这些值,然后进行修改
//-----------------------下面代码是传值--------------
int ID;
ID = dgvInformation.CurrentCell.RowIndex;
MyAccountUpdate frm = new MyAccountUpdate();
DataTable dt = new DataTable();
dt = (DataTable)dgvInformation.DataSource;
frm.txtExplain.Text = dt.Rows[ID]["说明"].ToString();
frm.txtMain_id.Text = dt.Rows[ID]["编号"].ToString(); if (Convert.ToInt32(dt.Rows[ID]["类型"]) == 0)//数值类型转化
{
frm.txtMoney.Text = dt.Rows[ID]["金额"].ToString();
frm.cboIncome.Text = dt.Rows[ID]["项目"].ToString();
}
if (Convert.ToInt32(dt.Rows[ID]["类型"]) == 1)
{
frm.txtMoney.Text = dt.Rows[ID]["金额"].ToString();
frm.cboOutcome.Text = dt.Rows[ID]["项目"].ToString();
}
frm.dtpkDate.Text = dt.Rows[ID]["收支日期"].ToString();
frm.ShowDialog();
值传过来了,也能在这个窗体上显示了,在进行update的时候,就不会了!!!!
怎么写啊
谢谢了!!!
在线等!!!!!!
string MyConn = "server=SQLOLEDB;Data Source=OOCO8HPY5V6TMKN;User ID=sa;Initial Catalog=Licai";
SqlConnection MyConnection = new SqlConnection(MyConn);
//-----------------select语句--------------------
SqlCommand MyCommand = new SqlCommand("select Main_ID as 编号,IO_Date as 收支日期,Type as 类型,Project as 项目,Money as 金额,Explain as 说明,Mark as 删除标记 from Pocket_book,Project_book where Pocket_book.A_ID = Project_book.A_ID and Pocket_book.B_ID = Project_book.B_ID", MyConnection);DataTable dt = new DataTable();
SqlDataAdapter SelectAdapter = new SqlDataAdapter();//定义一个数据适配器
SelectAdapter.SelectCommand = MyCommand;//定义数据适配器的操作指令
DataSet MyDataSet = new DataSet();//定义一个数据集
MyConnection.Open();//打开数据库连接
SelectAdapter.SelectCommand.ExecuteNonQuery();//执行数据库查询指令
SelectAdapter.Fill(MyDataSet, "Pocket_book");
System.Text.StringBuilder strSql = new System.Text.StringBuilder();
dgvInformation.AutoGenerateColumns = true;
dgvInformation.DataSource = MyDataSet.Tables[0];
DataTable dt = MyDataSet.Tables[0];在datagridview上显示,双击某一行进行修改,将这一行的值传给下一个窗体,在下一个窗体用几个textbox
控件显示这些值,然后进行修改
//-----------------------下面代码是传值--------------
int ID;
ID = dgvInformation.CurrentCell.RowIndex;
MyAccountUpdate frm = new MyAccountUpdate();
DataTable dt = new DataTable();
dt = (DataTable)dgvInformation.DataSource;
frm.txtExplain.Text = dt.Rows[ID]["说明"].ToString();
frm.txtMain_id.Text = dt.Rows[ID]["编号"].ToString(); if (Convert.ToInt32(dt.Rows[ID]["类型"]) == 0)//数值类型转化
{
frm.txtMoney.Text = dt.Rows[ID]["金额"].ToString();
frm.cboIncome.Text = dt.Rows[ID]["项目"].ToString();
}
if (Convert.ToInt32(dt.Rows[ID]["类型"]) == 1)
{
frm.txtMoney.Text = dt.Rows[ID]["金额"].ToString();
frm.cboOutcome.Text = dt.Rows[ID]["项目"].ToString();
}
frm.dtpkDate.Text = dt.Rows[ID]["收支日期"].ToString();
frm.ShowDialog();
值传过来了,也能在这个窗体上显示了,在进行update的时候,就不会了!!!!
怎么写啊
谢谢了!!!
在线等!!!!!!
解决方案 »
- 安装了sql server,再安装VS的问题
- 删除DataGridView行
- 求推荐一个C#或者.net的内存监控工具
- listview中,如何实现 单击某行里任意一列则改变该行背景
- 如何让覆盖在panel1上的panel2与panel1有点边距?一指定DOCK,边距就一样了
- 大家看看为什么我的2005这样?
- 关于Remoting的远程对象的获取
- LogonUser + CreateProcessAsUser 在windows服务中调用 外部exe程序 ,求高人指点
- 一个C#的问题! 多重查询!!!
- 100分!熟悉WMI的朋友请看!思归大侠请进
- 未处理 Win32Exception
- C# 自定义网络协议的问题,怎样写协议才可以使发送byte[]数组到服务端后服务端可以轻松解析成键值对形式,或者说怎样写既方便传输又方便解析
不会写Update语句????
值不是过来了吗
SqlCommand cmd = new SqlCommand("update xx set xx = 0 where xx = 1", cn);
cn.Open();
MessageBox.Show(cmd.ExecuteNonQuery().ToString());
cn.Close();