I appreciate what you have done BoulderBum, but unfortunately, I still don't know what is going on in that code. I have seen fifteen thousand ways of doing it, but none seem to work, or perhaps I'm missing some steps. Here is that I have managed to create using vb studio.net 2003, this is a dumbed down version of my actual real form, but if you can help me with one field, then it's just a matter of applying that to the rest.
The aspx code is as follows:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="inserttest.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="newInsert" style="Z-INDEX: 101; LEFT: 54px; POSITION: absolute; TOP: 64px" runat="server"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 83px; POSITION: absolute; TOP: 135px" runat="server"
Text="Button"></asp:Button>
</form>
</body>
</HTML>
And the behind code is:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace inserttest
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Web.UI.WebControls.TextBox newInsert;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Main", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("prim", "prim"),
new System.Data.Common.DataColumnMapping("inserted", "inserted")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT prim, inserted FROM Main";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO Main(inserted) VALUES (@insert); SELECT prim, inserted FROM Main";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@inserted", System.Data.SqlDbType.VarChar, 10).Value=newInsert.Text);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "Server=[server];Database=surveyform;User ID=sa;Password=private;Trusted_Connection=False";
this.sqlConnection1.InfoMessage += new System.Data.SqlClient.SqlInfoMessageEventHandler(this.sqlConnection1_InfoMessage);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void sqlConnection1_InfoMessage(object sender, System.Data.SqlClient.SqlInfoMessageEventArgs e)
{
}
private void Button1_Click(object sender, System.EventArgs e)
{
this.sqlInsertCommand1.Connection.Open();
this.sqlInsertCommand1.ExecuteNonQuery();
}
}
}
It connects to the database, but I get the following error:
The SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects.
Any ideas?