Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
I'm new to this coding game so I need a bit of assistance

I need to build a simple Website using VS2012 VB.NET,

I have a simple test website that contains 1 textbox(name) - 1 dropdown (gender) - and a calendar (dob)

with a SQL database (TSTWEBDEV) With the columns 'Name' 'Gender' 'DOB'

Data Source=TSTWEBDEV;Initial Catalog=TestWebAp;User ID=testWA;Password=12345

I have a submit button

protected void Button1_Click(object sender, EventArgs e)

Question is what is the code to insert this into the DB?

easy one for those who know! :)
any help will be great! thanks
Posted

Try something like this:
VB
Using con As New SqlConnection(strConnect)
    con.Open()
    Using cmd As New SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con)
        cmd.Parameters.AddWithValue("@C1", myValueForColumn1)
        cmd.Parameters.AddWithValue("@C2", myValueForColumn2)
        cmd.ExecuteNonQuery()
    End Using
End Using
 
Share this answer
 
Comments
OriginalGriff 22-Dec-13 11:53am    
If you mean "can I have your email?" the answer is "no!" :laugh:
I get enough emails every day, I don't need any more, thanks!
If you have specific areas of confusion, then ask here about them. (That way, others see them too, so you may get responses from more than one person - which can be helpful at times)
Member 10481933 22-Dec-13 12:05pm    
hahaha ah bummer! no worries, will have a dig at it and see what i can find :)
OriginalGriff 22-Dec-13 12:14pm    
Go for it! :laugh:
VB
Dim objcon As New SqlConnection
objcon.ConnectionString = My.Settings.CS
objcon.Open()

  
Dim objcmd As New SqlCommand("Insert into table([name],gender,dob) values('" + txtname.Text.Trim + "','" + ddl.Text.Trim+ "','" + Calendar1.SelectedDate.ToString("dd/MM/yyyy") + "')", objcon)
                objcmd.ExecuteNonQuery()


try this

Regards
AravindB
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900