私は大学のプロジェクト用にASP.NET Webアプリケーションを作成しましたが、ローカルmysql db 。私のコントロール外の理由により、私はアクセス・データベースにデータベースを変更するよう指示されました。だから私はこれを行って、 'Oledb'のものの 'SQL'ステートメントを変更し、私のアプリケーションの半分は新しい変更で正常に動作しますが、私は他の半分に問題があります。私はweb.configページから接続文字列を追加し、それに続いて問題があります。誰かが私が間違っている場所を見ることができますか?ASP.NET Webアプリケーション - 私のデータベース接続に問題があり、データベースにアクセスするためにmysqlを切り替えてから
<add name="newregDBConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Alex\Documents\Database1.accdb"
providerName="System.Data.OleDb" />
私が最初に私は登録ページを持っているということである二つの問題を、持っている、あなたは、フォームに必要事項を記入し、詳細は、データベースに格納されています。 DBに詳細を送信するためにsubmitをクリックすると、エラーが発生します。
第二の問題は、私がデータソースを使用してGridViewのを、持っているということである登録ユーザーが表示されますが、私はビュー]ボタンをクリックしたときに、私は次のエラーを取得します。
I "は、([newregDBConnectionString"]新しい 例外ConfigurationManager.ConnectionStrings投げる "
を追加のConnectionStringします。);"エラーを表示するには をmy global.aspxページに追加してください。
それは私の接続文字列は、私のweb.configページで間違っていますが、私のアプリの他の半分は、データベース接続(私のログインページ)で働いているので、私は「できているかのように、それが思われてしまいます問題を参照してください。長いポストのお詫び、私はどこの人が私が愚かなのかを指摘してくれたことを大変感謝しています!前もって感謝します。
更新日:newregDBConnectionString
が引用符で囲まれている
OleDbConnection connect = new OleDbConnection("newregDBConnectionString");
ていることに注意してください:この時
protected void submitBtn_Click(object sender, EventArgs e)
{
OleDbConnection connect = new OleDbConnection(ConfigurationManager.ConnectionStrings["newregDBConnectionString"].ConnectionString);
{
if (parentRadBtn.Checked)
{
if (firstNameBox.Text == "" || surnameBox.Text == "" || postcodeBox.Text == "" || teleBox.Text == "" || emailBox.Text == "" || userBox.Text == "" || passwordBox.Text == "")
{
Response.Write("<script>alert('Please ensure all fields have an entry');</script>");
successLabel.Text = ("");
userBox.Text = "";
firstNameBox.Text = "";
surnameBox.Text = "";
postcodeBox.Text = "";
teleBox.Text = "";
emailBox.Text = "";
passwordBox.Text = "";
}
else
{
OleDbCommand pa = new OleDbCommand("INSERT INTO parent(parentID, firstname, surname, postcode, telephone, email, password) VALUES (@parentID, @firstname, @surname, @postcode, @telephone, @email, @password)", connect);
pa.Parameters.AddWithValue("@parentID", userBox.Text);
pa.Parameters.AddWithValue("@firstname", firstNameBox.Text);
pa.Parameters.AddWithValue("@surname", surnameBox.Text);
pa.Parameters.AddWithValue("@postcode", postcodeBox.Text);
pa.Parameters.AddWithValue("@telephone", teleBox.Text);
pa.Parameters.AddWithValue("@email", emailBox.Text);
pa.Parameters.AddWithValue("@password", passwordBox.Text);
connect.Open();
pa.ExecuteNonQuery();
connect.Close();
}
if (IsPostBack)
{
userBox.Text = "";
firstNameBox.Text = "";
surnameBox.Text = "";
postcodeBox.Text = "";
teleBox.Text = "";
emailBox.Text = "";
passwordBox.Text = "";
}
}
else if (childRadBtn.Checked)
{
if (firstNameBox.Text == "" || dayDobList.Text == "" || monthDobList.Text == "" || yearDobList.Text == "" || genderList.Text == "" || userBox.Text == "" || passwordBox.Text == "")
{
Response.Write("<script>alert('Please ensure all fields have an entry');</script>");
successLabel.Text = ("");
userBox.Text = "";
firstNameBox.Text = "";
dayDobList.Text = "";
monthDobList.Text = "";
yearDobList.Text = "";
genderList.Text = "";
passwordBox.Text = "";
}
else
{
OleDbParameter dob = new OleDbParameter("@dob", System.Data.SqlDbType.DateTime);
dob.Value = new DateTime(Int32.Parse(yearDobList.Text), Int32.Parse(monthDobList.Text), Int32.Parse(dayDobList.Text));
OleDbCommand ca = new OleDbCommand("INSERT INTO children(childID, firstname, dob, gender, password) VALUES (@childID, @firstname, @dob, @gender, @password)", connect);
ca.Parameters.AddWithValue("@childID", userBox.Text);
ca.Parameters.AddWithValue("@firstname", firstNameBox.Text);
ca.Parameters.Add(dob);
ca.Parameters.AddWithValue("@gender", genderList.Text);
ca.Parameters.AddWithValue("@password", passwordBox.Text);
connect.Open();
ca.ExecuteNonQuery();
connect.Close();
}
if (IsPostBack)
{
userBox.Text = "";
firstNameBox.Text = "";
dayDobList.Text = "";
monthDobList.Text = "";
yearDobList.Text = "";
genderList.Text = "";
passwordBox.Text = "";
}
}
}
}
ログインページとして、それは同じ作るあなただけの文字列
を渡している私だと思うしている間、あなたのログインページがこの
を持っています実際のライブデータベースがあります。ほぼすべてのDBエンジンには、標準にほぼ準拠した独自のSQL方言があります。どちらもMySqlもAccessもここでは特に優れていません。私はもはやMySqlが現代のDBエンジンであるとはもはや考えていません(それは過去10年の間に崩壊してしまっています)。また、Accessはインプロセスエンジンであり、Webサイトにとっては全く不適切な選択です。しかし、課題は課題であり、実践的な理由からしばしば人為的な制約があります。結果として、すべてのSQL文を調べてAccessで動作することを確認する必要があります。 –
そして、あなたの質問からコピー/貼り付けの代わりにあなたのコードを再入力してくれてありがとう。私たちは本当にそれを感謝します。私は真剣です。 –
@JoelCoehoornええ、私はそれをMySQLでうまく動作させましたが、私が言ったように、私たちの教授は私たちがアクセスに切り替えることを望みます。あなたのフォローアップのコメントで皮肉なことだと思うし、私はいつも自分のコードを貼り付けるが、それは見なければならないコードの塊ではないと思った、それはスクリーンショットで見ることができる。コードを使って自分自身をテストする人にとってはより多くのことを認識しました。私はそのようなことは考えませんでした。申し訳ありません、将来的に投稿する場合は、私は間違いなくより慎重になります。 – ACostea