這是我第一個需要sql數據庫的asp.net web應用程序。我使用表格和我的Web服務器上需要的所有列來配置數據庫。我的sql數據庫表中沒有什麼?
我做了什麼至今在web.config中:
<connectionStrings> <add name="MyConnectionString" connectionString="Data Source=; Initial Catalog=; User ID=; Password=;" providerName="System.Data.SqlClient" /> </connectionStrings>
和簡單的申請表:
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource nexusdb = new SqlDataSource();
nexusdb.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString();
nexusdb.InsertCommandType = SqlDataSourceCommandType.Text;
nexusdb.InsertCommand = "INSERT INTO Windows (Firstname, Lastname, Email, Phone, Company, Date, IPAddress) VALUES (@Firstname, @Lastname, @Email, @Phone, @Company, @Date, @IPAdress)";
nexusdb.InsertParameters.Add("Firstname", FirstNametxtbox.Text);
nexusdb.InsertParameters.Add("Lastname", LastNametxtbox.Text);
nexusdb.InsertParameters.Add("Email", Emailtxtbox.Text);
nexusdb.InsertParameters.Add("Phone", Phonetxtbox.Text);
nexusdb.InsertParameters.Add("Company", Companytxtbox.Text);
nexusdb.InsertParameters.Add("Date", DateTime.Now.ToString());
nexusdb.InsertParameters.Add("IPAddress", Request.UserHostAddress.ToString());
}
但是沒有在我的表?!
你在哪裏執行命令? – lluismontero
在提交按鈕中:<%@ Page Language =「C#」AutoEventWireup =「true」CodeFile =「contact_us.aspx.cs」Inherits =「contact_us」%> –