0

I want to get a value of a cell from access database where value of "fdne1" column is textBox1.text in other words I dont know "statment" code in below code what should be my database columns are fdne1, fee

string statement =??????????? */Select * From Table2 where fdne1 valve is textBox1.text
OleDbCommand MyOleDbComm2 = new OleDbCommand();
                        ObjConn2.Open();
                        MyOleDbComm2.CommandText =
                            "UPDATE Table2 " +
                            "SET fee="+ statment +
                            " Where(Table2.fdne1)='" + textBox1.Text + "'";
                        MyOleDbComm2.Connection = ObjConn2;
                        MyOleDbComm2.ExecuteNonQuery();
                        ObjConn2.Close();

My database is access and has 2 tables ,table2 have 2 columns I want to get value of "fee" column in a row that "fdne1" value is somthing like textbox1.text and put it to a string or convert it to int then I do some mathematic processes on it and put the new value on database I can edit database but I want value of the cell that I said Sorry for bad English :)

4

2 回答 2

0

为什么不使用 Access 查询设计器,然后复制并粘贴 SQL?

于 2013-08-09T14:29:34.177 回答
0

您应该知道 SQL 有一些语句,例如:

Select to select value(s) from table
Update to update value(s) from table
...

如果您想获取表格中一个单元格的值,您应该使用 select 语句。

像这样:从“您的表”中选择“您的列”,其中“您过滤列的条件”

请注意,根据您的情况,结果可能会返回多个值。如果要更新表中的值,请使用如下更新语句:

更新“你的表”设置“你的列=新值”,其中“你的条件是在列内找到值”

请更明确,我会提供更多信息。

如果我必须正确,那么我可以尝试给你一些代码示例:

OleDbCommand MyOleDbComm2 = new OleDbCommand();
ObjConn2.Open();

MyOleDbComm2.CommandText = "Select fee from table2 " + 
                           " Where Table2.fdne1='" + textBox1.Text + "'";
MyOleDbComm2.Connection = ObjConn2;

var result= MyOleDbComm2.ExecuteScalar();

ObjConn2.Close();
于 2013-08-09T14:21:36.820 回答