0
我想將數據插入到.mdf
SQL Server文件中,但是當我想要查看我插入的數據時。這沒有發生。我使用本地數據庫進行工作。無法將數據從C#插入到SQL Server中
private SqlConnection connection;
private SqlCommand command;
private string sql;
private void frmNewEmp_Load(object sender, EventArgs e)
{
string conStr = @"Server=(localdb)\v11.0;AttachDbFilename=|DataDirectory|\Payrolldatabase.mdf;";
connection = new SqlConnection(conStr);
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
}
private void InsertData()
{
sql = @"INSERT INTO Employee(EID, EName, EAdd, ESSID, ETel, EDatesub, ESalary) VALUES(@id, @name, @add, @ssid, @tel, @date, @sal)";
command = new SqlCommand(sql, connection);
command.Parameters.Clear();
command.CommandText = sql;
AddParamterValues();
MessageBox.Show("Add complete");
}
打開連接負載這方面,但從來沒有關閉 –
這是工作。謝謝你的幫助。 – kawaiipeace