作者klein (爱新觉罗)
看板C_Sharp
标题Re: [问题] 想传一个参数阵列到函式.
时间Sat Nov 27 21:22:15 2004
※ 引述《seagal (待救的小米)》之铭言:
恕删.
不好意思, seagal前辈,还是有几个小问题希望指点.
: private void btnFind_Click(object sender, System.EventArgs e)
: {
: // The SqlDataReader class provides a way to read a forward-only
: // stream of rows from a Sql Server database
: SqlDataReader drEmployee = null;
: try
: {
: // Open connection to the database
: sqlConnection1.Open();
: // Fill the parameter with the value retrieved from the text field
: sqlCommand1.Parameters["@Find"].Value = txtFind.Text;
这里是要在main里面设定我知道.
但是设定之後在function里面要怎麽读取呢? @@
我原本以为只要再传入的SQL里面有写,就可以自己抓到了.
不过看来我错了.
: // Execute the query
: drEmployee = sqlCommand1.ExecuteReader();
: // Fill the list box with the values retrieved
: lbFound.Items.Clear();
: while(drEmployee.Read())
: {
: lbFound.Items.Add(drEmployee["FirstName"].ToString() + " " +
: drEmployee["LastName"].ToString());
: }
: }
: catch(Exception ex)
: {
: // Print error message
: MessageBox.Show(ex.Message);
: }
: finally
: {
: // Close data reader object and database connection
: if (drEmployee != null)
: drEmployee.Close();
: if (sqlConnection1.State != ConnectionState.Closed)
: sqlConnection1.Close();
: }
: }
: 第二种方式
: 是利用Dataset & Data Adaptor
: 来修改资料库
: // Change the value in the DataSet
: ds.Tables[0].Rows[8]["FirstName"] = "Anna";
: // Re-connect to the data source
: cn.Open();
: // Create an OleDbCommandBuilder object, passing the DataAdapter
: // into the constructor
: OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(da);
: // Display the UpdateCommand
: Console.WriteLine(cmdBuilder.GetUpdateCommand().CommandText);
: // Update the data source
: da.Update(ds.Tables[0]);
: // Close the connection again
: cn.Close();
: 如果你可以使用ADO.NET 2.0
: 那就可以使用最方便的第三种方式
: 使用SQLDataSource
: 搭配ASP.NET & Visual Studio .NET 2005
: 可以不用写任何一行程式码
: 就完成修改 存取资料库
: 若是要自己操作SQLDataSource
: 一样也很简单
: ※ 引述《klein (爱新觉罗)》之铭言:
: : 可以说的更清楚一点吗? @@
: : 用sqlparameter不是就是ADO.NET吗?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 163.13.11.123