inserting data-error-help me,its urgent

Sub inserting(ByVal s As Object, ByVal e As EventArgs)
Dim con1 As SqlConnection
Dim cmd As SqlCommand
con1 = New SqlConnection("Data Source=YOUR-41B8D18EDE;Initial Catalog=employee;Integrated Security=True")
con1.Open()
Dim insertvalues As String = "insert into registertable(@surname)values(textbox)"
'in above line i am getting error'
cmd = New SqlCommand(insertvalues, con1)
cmd.Parameters.Add(New SqlParameter("@name", SqlDbType.NVarChar, 11)).ToString()
cmd.Parameters("@name").Value = TextBox1.Text


cmd.ExecuteNonQuery()
con1.Close()

End Sub

Comments

  • seancampbellseancampbell Pennsylvania, USA
    First I'd like to mention, if you have an urgent issue, your best bet to get an answer to help you....... is to explain the code and the problem that you have posted. (a comment that says "it crashes here" generally is not enough, the full details of the exception that is getting thrown is the most helpful).

    And as to your problem:

    1.
    The first thing I see is that you have no Username , Password, and possibly no IP address in your Connection string (You have some YOUR-41B8D18EDE, maybe that is a DNS name)

    for help with connection strings check out (http://www.connectionstrings.com/) and click on the link to the Database type you are connecting to.

    2.
    You have formed your Insert statement oddly, I don't think it's going to work at all...

    INSERT INTO table_name (column1, column2, column3,...)
    VALUES (value1, value2, value3,...)

    [code]
    Dim insertvalues as String = "INSERT INTO registertable(surname) VALUES (@name)"
    cmd = New SqlCommand(insertvalues, con1)
    cmd.Parameters.Add(New SqlParameter("@name", SqlDbType.NVarChar, 11)).ToString()
    cmd.Parameters("@name").Value = TextBox1.Text
    [/code]

    In the code above, I made the assumption that surname is the column in the Registertable Table. In the values area, I put in the parameter @name, which you were referencing in your parameter code...

    Hope this helps
    Seancampbell, vb.net forum mod, firesickle.com
  • seancampbellseancampbell Pennsylvania, USA
    For more help with forming SQL statements
    http://www.w3schools.com/SQL/sql_insert.asp
  • seancampbellseancampbell Pennsylvania, USA
    I had to check to make sure I was doing the parameter part right, I don't know if the other code will work. If it doesn't, try:
    [code]
    Dim insertvalues as String = "INSERT INTO registertable(surname) VALUES (@name)"
    cmd = New SqlCommand(insertvalues, con1)
    cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = TextBox1.Text
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion