Re: [問題] 想傳一個參數陣列到函式.

看板C_Sharp (C#)作者 (愛新覺羅)時間20年前 (2004/11/27 20:22), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/7 (看更多)
※ 引述《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
文章代碼(AID): #11g76X_I (C_Sharp)
文章代碼(AID): #11g76X_I (C_Sharp)