You need to explain us bit more, like which connection you have used in your application such as ADO.Net, Entity Framework or LINQ TO SQL, how you are populating data on page.
Here is how you can do using ADO.Net. Preferably use the Stored procedure to update. But if this is for your test then u can direclty write query. I assume you have a asp.net page which has text boxes populated with data.
' Create database connection
Dim con as new new SqlConnection(@"Data Source=WNPCCSG03\SQL08;Initial Catalog=MiscTest;uid=sa;Password=CsgGr0up")
' create command object. Assign query and connection
dim cmd as new SqlCommand("update CustomerDetails set address=@Add where CustID=@CustID",con)
' Tell the command type, here you can select Storedprocedure and give SP name instead of above query
cmd.CommandType=CommandType.Text
' Add two parameter as below which feed into above query
cmd.Parameters.AddWithValue(@Add, TxtCustAdd.text)
cmd.Parameters.AddWithValue(@CustID, TxtCustID.text)
' Opecn connection, execute query and close connection
con.Open()
cmd.ExecuteNonQuery()
con.Close()
' data should updated into the DB
Note: I have quickly written code, just copy and paste to the code editor make changes where needed.
Dim Cmd As New SqlClient.SqlCommand
Try
Using SqlConnection As New SqlClient.SqlConnection(Connectionstring)
Cmd.CommandType = CommandType.StoredProcedure
Cmd.CommandText = "tblProgressMonthStatusUpdate" ' Your Stored Procedure Name
Cmd.Parameters.Add("id", SqlDbType.Int).Value = idSession ' Your primary key
Cmd.Connection = SqlConnection
SqlConnection.Open()
Cmd.ExecuteNonQuery()
End Using
Catch ex As Exception
'Error Handling
Finally
If Not Cmd Is Nothing Then
Cmd = Nothing
End If
End Try
I considered that you know how to get connection string and how to make stored procedure.
RITU11
0 Points
2 Posts
Want to update database(SQL server) Using ASP.NET
Nov 22, 2012 05:53 AM|LINK
I have some table in database. I want to modify that table need to modify data in only one column using aspx.vb
Please help me in this, how can i modify already existing database?
oned_gk
All-Star
31776 Points
6493 Posts
Re: Want to update database(SQL server) Using ASP.NET
Nov 22, 2012 06:10 AM|LINK
Use gridview - sqldatasource, autogenerate insert/update/delete
set some column readonly.
RITU11
0 Points
2 Posts
Re: Want to update database(SQL server) Using ASP.NET
Nov 22, 2012 06:14 AM|LINK
Grid vied i dont know how to use.
I am new for .NET :(
Please provide some link for help or some Code
pratiksolank...
Member
271 Points
76 Posts
Re: Want to update database(SQL server) Using ASP.NET
Nov 26, 2012 07:09 PM|LINK
Hi,
You need to explain us bit more, like which connection you have used in your application such as ADO.Net, Entity Framework or LINQ TO SQL, how you are populating data on page.
Here is how you can do using ADO.Net. Preferably use the Stored procedure to update. But if this is for your test then u can direclty write query. I assume you have a asp.net page which has text boxes populated with data.
' Create database connection Dim con as new new SqlConnection(@"Data Source=WNPCCSG03\SQL08;Initial Catalog=MiscTest;uid=sa;Password=CsgGr0up") ' create command object. Assign query and connection dim cmd as new SqlCommand("update CustomerDetails set address=@Add where CustID=@CustID",con) ' Tell the command type, here you can select Storedprocedure and give SP name instead of above query cmd.CommandType=CommandType.Text ' Add two parameter as below which feed into above query cmd.Parameters.AddWithValue(@Add, TxtCustAdd.text) cmd.Parameters.AddWithValue(@CustID, TxtCustID.text) ' Opecn connection, execute query and close connection con.Open() cmd.ExecuteNonQuery() con.Close() ' data should updated into the DBNote: I have quickly written code, just copy and paste to the code editor make changes where needed.
Regards,
Pratik
nikunjnandan...
Participant
882 Points
223 Posts
Re: Want to update database(SQL server) Using ASP.NET
Nov 27, 2012 04:25 AM|LINK
Hii,
you can use below code.
Dim Cmd As New SqlClient.SqlCommand Try Using SqlConnection As New SqlClient.SqlConnection(Connectionstring) Cmd.CommandType = CommandType.StoredProcedure Cmd.CommandText = "tblProgressMonthStatusUpdate" ' Your Stored Procedure Name Cmd.Parameters.Add("id", SqlDbType.Int).Value = idSession ' Your primary key Cmd.Connection = SqlConnection SqlConnection.Open() Cmd.ExecuteNonQuery() End Using Catch ex As Exception 'Error Handling Finally If Not Cmd Is Nothing Then Cmd = Nothing End If End TryI considered that you know how to get connection string and how to make stored procedure.
Nikunj Nandaniya
My Blog