How To Get The Table Connected In My Webform In Asp.net?

January 14th, 2010 by CTO WebOjO.com website designers Lahore Pakistan Leave a reply »

i’m not using datagrid.. i created 1 table wid follwg steps:
IN server Control i added 1 table
in my webform i took one connection object.
now i want that terxtbox entries in my form should be inserted in that table.. what should i do then?

Advertisement

1 comment

  1. caden says:

    This is just a sample code. you do not need to understand everything but you see the general idea. You create the connection object, bind the parameters with your textbox entries and then open the connection and execute.
    Dim conn As SqlConnection = New SqlConnection(strSqlConnection)
    Dim strInsertSql As String
    strInsertSql = “insert into pharmex_Institutions ” _
    & “(InstitutionName, Address, City, Area, Phone, PostCode, Devices) ” _
    & “values ” _
    & “(@InstitutionName, @Address, @City, @Area, @Phone, @PostCode, @Devices)”
    Dim cmdInsertSql As SqlCommand = New SqlCommand(strInsertSql, conn)
    ‘ catch all checkboxlist selections
    Dim deviceid As ListItem
    Dim strDevicesList As String = “”
    For Each deviceid In lstDevices.Items
    If deviceid.Selected Then
    strDevicesList = strDevicesList & “,” & deviceid.Value
    End If
    Next
    cmdInsertSql.Parameters.AddWithValue(”@D… strDevicesList)
    cmdInsertSql.Parameters.AddWithValue(”@I… txtInstitutionName.Text)
    cmdInsertSql.Parameters.AddWithValue(”@A… txtAddress.Text)
    cmdInsertSql.Parameters.AddWithValue(”@C… txtCity.Text)
    cmdInsertSql.Parameters.AddWithValue(”@A… txtArea.Text)
    cmdInsertSql.Parameters.AddWithValue(”@P… txtPhone.Text)
    cmdInsertSql.Parameters.AddWithValue(”@P… txtPostCode.Text)
    conn.Open()
    cmdInsertSql.ExecuteNonQuery()
    conn.Close()