私は私のASP.NET Webサイトにデータベースに接続しようとしていたとは、このエラーが発生しましたASP.NETのWebサイトへのユーザコードConnectデータベースによって、未処理でした私はVisual Studio Coommunity 2015を使用しています。これは私のC#コードです。SQL例外が
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class CompleteOrder : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Random rnd = new Random();
int ordernum = rnd.Next(3, 10000);
string Name = Request.QueryString["name"];
string IC = Request.QueryString["ic"];
string Contact = Request.QueryString["contact"];
string Date = Request.QueryString["date"];
string Seats = (string) (Session["seats"]);
Label7.Text = Convert.ToString(ordernum);
Label4.Text = Name;
Label8.Text = IC;
Label10.Text = Contact;
Label12.Text = Date;
Label14.Text = Seats;
SqlConnection con = new SqlConnection(@"Data Source=PELim;Initial Catalog=airplane_reservation;Integrated Security=True;Pooling=False");
con.Open();
SqlCommand cmd =new SqlCommand("INSERT INTO Airplane_Reservation(Order_Number,Name,Identification_Number, Contact_Number, Departure_Date, Seats)VALUES('" + ordernum + "','" + Name + "','" + IC + "','" + Contact + "', '" + Date + "', '" + Seats + "')", con);
cmd.ExecuteNonQuery();
con.Close();
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("Main.aspx");
}
}
お手数ですが、よろしくお願いいたします。
デシベルでユーザーを追加しようとすると、接続文字列を更新します。ところで、web.configでは接続文字列を使用し、コードでは直接使用しないでください。 –
あなたはこのデータベースのユーザーを作成して、接続文字列でログインして変更することを意味しますか? @SanishJoseph –
はい。それが私の言いたいことです。適切な権限を持つ役割を与えます。 –