0
我成功發佈了格式化字符串以訪問數據庫,但字符串沒有插入到行中,而是它們都排成一行。我不知道如何將數據從富文本字段發佈到ms訪問行
private void viewLog_Click(object sender, EventArgs e)
{
string status = this.statusDisplay.Text;
string time = this.logtimeDispaly.Text;
try
{
for (int rows = 0; rows < status.Length; rows++)
{
//create a new connection
OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = ElevatorStatusLog.mdb");
//open the connection
connection.Open();
//create a query
OleDbCommand command;
command = new OleDbCommand("INSERT INTO StatusLog([DateTime],[Activities]) VALUES(@Parameter1, @Parameter2)", connection);
command.Parameters.Add(new OleDbParameter("@Parameter1", time.ToString()));
command.Parameters.Add(new OleDbParameter("@Parameter2", status.ToString()));
command.ExecuteNonQuery();
connection.Close();
}
}
catch (Exception err)
{
MessageBox.Show(err.Message.ToString());
}
這應該被插入到行中。請幫幫我。謝謝
非常感謝Soner。 – Progzilla 2014-12-06 16:47:22
它會拋出任何異常嗎? – Patrick 2014-12-06 16:50:01
不,它不。它有效但不正確。從富文本中將約4行字符串插入到訪問中的一行中。這就是爲什麼我嘗試使用for循環來糾正這個問題。 – Progzilla 2014-12-06 16:54:16