第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

ExecuteNonQuery:連接屬性尚未初始化。

ExecuteNonQuery:連接屬性尚未初始化。

C#
人到中年有點(diǎn)甜 2019-11-03 08:04:17
下午,所以我在這個(gè)問題上待了好幾個(gè)小時(shí),無法真正克服最后一個(gè)困難。以下是我正在編寫的該程序的代碼:using System;  using System.Collections.Generic;  using System.Linq;  using System.Text;  using System.Diagnostics;  using System.Data;  using System.Data.SqlClient;  using System.Configuration;  namespace Test  {    class Program    {      static void Main()      {        EventLog alog = new EventLog();        alog.Log = "Application";        alog.MachineName = ".";        foreach (EventLogEntry entry in alog.Entries)        {         SqlConnection connection1 = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=syslog2;Integrated Security=True");         SqlDataAdapter cmd = new SqlDataAdapter();         cmd.InsertCommand = new SqlCommand("INSERT INTO Application VALUES (@EventLog, @TimeGenerated, @EventType, @SourceName, @ComputerName, @InstanceId, @Message) ");         cmd.InsertCommand.Parameters.Add("@EventLog",SqlDbType.VarChar).Value = alog.Log;         cmd.InsertCommand.Parameters.Add("@TimeGenerated", SqlDbType.DateTime).Value = entry.TimeGenerated;         cmd.InsertCommand.Parameters.Add("@EventType", SqlDbType.VarChar).Value = entry.EntryType;         cmd.InsertCommand.Parameters.Add("@SourceName", SqlDbType.VarChar).Value = entry.Source;         cmd.InsertCommand.Parameters.Add("@ComputerName", SqlDbType.VarChar).Value = entry.MachineName;         cmd.InsertCommand.Parameters.Add("@InstanceId", SqlDbType.VarChar).Value = entry.InstanceId;         cmd.InsertCommand.Parameters.Add("@Message", SqlDbType.VarChar).Value = entry.Message;         connection1.Open();         cmd.InsertCommand.ExecuteNonQuery();         connection1.Close();        }       }    }  } 該代碼可以正常編譯,沒有錯(cuò)誤或警告,但是當(dāng)我運(yùn)行它時(shí),只要它到達(dá)cmd.InsertCommand.ExecuteNonQuery();就可以了。我收到以下錯(cuò)誤:ExecuteNonQuery:連接屬性尚未初始化。關(guān)于我錯(cuò)過的任何想法?
查看完整描述

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);



查看完整回答
反對 回復(fù) 2019-11-04
?
慕村225694

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);



查看完整回答
反對 回復(fù) 2019-11-04
  • 3 回答
  • 0 關(guān)注
  • 1016 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)