Wednesday, August 18, 2010

How to get the table connected in my webform in ASP.NET?

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?How to get the table connected in my webform in ASP.NET?
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 '; _


%26amp; ';(InstitutionName, Address, City, Area, Phone, PostCode, Devices) '; _


%26amp; ';values '; _


%26amp; ';(@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 %26amp; ';,'; %26amp; 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()

No comments:

Post a Comment