私は、既存のデータベース行にデータを追加するWebアプリケーションを作成しています。私の場合、ボタンをクリックすると、NULL値を持つ列にデータが挿入されるようにします。ASP.netでSystem.Data.SqlClient.SqlExceptionエラーを解決するにはどうすればよいですか?
ツアーに行く予定の人物の日付と人数を選択できるページがあり、[今すぐ予約]ボタンをクリックすると、日付と人物のデータをデータベースに追加する必要があります。
System.Data.SqlClient.SqlException: 'An attempt to attach an auto-named database for file C: \Users\xxx\Documents\xxx\Project\App_Data\Database.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.'
私の友人は、私は私の現在のデータベースを削除して、再度データベース全体をやり直す必要があります。このエラーを解決すると言ったが、私は見つける:私はボタンをクリックしたときのよう
ただし、このエラーが表示されます私はすでに大きなデータベースを設定しているので、非常に時間がかかり退屈です。
これらはボタンの私が持っているコードです:
protected void bookBtn_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C: \Users\xxx\Documents\XXX\Project\App_Data\Database.mdf;Integrated Security=True");
//SqlCommand cmd = new SqlCommand("Booking",con);
//not sure if this is correct
SqlCommand cmd = new SqlCommand("Update Tours set date = + '"+dateTextbox.Text+"', person = '"+personDLL.Text+"' Where [email protected]");
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("date", dateTextbox.Text);
cmd.Parameters.AddWithValue("person", personDLL.Text);
con.Open(); //error here
int k = cmd.ExecuteNonQuery();
if (k != 0)
{
lblmsg.Text = "Record Inserted Succesfully into the Database";
lblmsg.ForeColor = System.Drawing.Color.CornflowerBlue;
}
con.Close();
}
は、私は私のデータベース全体をやり直すことなく、次のエラーを解決することができる方法はありますか?
*私は、私はstackoverflowのは私がより良い説明のために画像をアップロードすることはできません10 reputtationを持っていないので、その
** C:\ Users \ g_jes \ ... **に** C:**の後にスペースがあるのはなぜですか? – maddy23285
スペースを削除してもエラーが発生した場合、データベースは実行できません。 @ maddy23285の前にこれを試しました – depressedGirl