3 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊
您不是在初始化連接,這就是為什么出現(xiàn)這種錯(cuò)誤的原因。
您的代碼:
cmd.InsertCommand = new SqlCommand("INSERT INTO Application VALUES (@EventLog, @TimeGenerated, @EventType, @SourceName, @ComputerName, @InstanceId, @Message) ");
更正的代碼:
cmd.InsertCommand = new SqlCommand("INSERT INTO Application VALUES (@EventLog, @TimeGenerated, @EventType, @SourceName, @ComputerName, @InstanceId, @Message) ",connection1);

TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊
您不是在初始化連接,這就是為什么出現(xiàn)這種錯(cuò)誤的原因。
您的代碼:
cmd.InsertCommand = new SqlCommand("INSERT INTO Application VALUES (@EventLog, @TimeGenerated, @EventType, @SourceName, @ComputerName, @InstanceId, @Message) ");
更正的代碼:
cmd.InsertCommand = new SqlCommand("INSERT INTO Application VALUES (@EventLog, @TimeGenerated, @EventType, @SourceName, @ComputerName, @InstanceId, @Message) ",connection1);
- 3 回答
- 0 關(guān)注
- 1016 瀏覽
添加回答
舉報(bào)