This is my first asp.net web application that needs a sql database. I configured the database with the table and all of the columns that I need on my webserver.
What i did so far is in web.config:
<connectionStrings>
<add name="MyConnectionString" connectionString="Data Source=; Initial Catalog=; User ID=; Password=;"
providerName="System.Data.SqlClient" />
</connectionStrings>
and in a simple application form:
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());
}
However nothing in my table ?!
Please read this article about Inserting Data Into a SQL Database. You will find it in both
C#andVBThis got good example of inserting data in to database