My god.
All I want to do is post the contents of a web form to a database sql express 2005 or access using C#. Why can I find nothing for this very simple process online?
Can you tell I am totally frustrated?
So lets say i have a few text fields and I want to click submit and have that entered into a table. I use C# for code behind. So I can do basic C# programming and I can to webforms with visual web developer 2005 dragging and dropping for textboxs and a button to the aspx page. But then the mystery begins for me. How the hell do I simple post that form data to the table. I understand connection string basics. I aslo can design and create tables.
But tying this all together is becoming a problem. I don't want to use gridview formview detailview or any of that canned UI stuff. I also don't understand VB and when I see VB examples they only cloud my already cloud ASP.NET world.
Please help by posting examples, and maybe some links or books to add to my newbish collection.
Thanks,
Frank
A very simplified example. Hope that will help
<form id="form1" runat="server"> <div> <asp:TextBox ID="txtInput" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtInput" ErrorMessage="Value needed"></asp:RequiredFieldValidator> <br /> <br /> <asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" /></div> </form>
and below is the button click event:
string cnStr =""//your connection string herestring valueToSave = txtInput.Text.Trim();string qry =""// your insert query here SqlConnection cn =new SqlConnection(cnStr);cn.Open();SqlCommand cm =new SqlCommand(qry, cn);int i = cm.ExecuteNonQuery();|||
Ok, this looks like what I am looking for but I have two other questions...but first here is my code:
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox><asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Button"/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>string cnStr ="";//connection string stuff here
string name = TextBox1.Text.Trim();
string qry ="insert into [name] value [name]";//insert statement here
SqlConnection cn =new SqlConnection(cnStr);
cn.Open();
SqlCommand cm =new SqlCommand(qry, cn);
int i = cm.ExecuteNonQuery();
when generating a connectionstring I see this in the wizard:
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True
I made a simple table called 'name' with a text field called 'name' (that sql statement up there might be incorrect as well.
My question is how do I properly format the connection string if it is in app_Data for my project called 'form'?
Second question is my SQL statement correct for inserting a value into 'name'?
Thanks,
Frank
|||
Answer to your second question is no, it will be something like - "insert into name value " ' " + name + " ' ".
And i did not get your first question. If you can provide a little more detail it will be helpful
No comments:
Post a Comment