Hello my friends programmers
This is my first question about this beautiful forum, which I love and have used for years.
How to Import JSON to SQL Server
I use this method which works fine only to import Json data into Grid View
I want to add body data in the database, how can I do that?
*************** Bringing Jason Data to Grid View ***************
Protected Sub Page_Load (ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim json As String = (New WebClient). DownloadString ("https://raw.githubusercontent.com/aspsnippets/test/master/Customers.json")
GridView1.DataSource = JsonConvert.DeserializeObject (Of DataTable) (json)
GridView1.DataBind ()
End If
End Sub
'' '' ********* Code for adding a new record in the database ********** ''
Public Sub Insert (name As String, country As String) Implements IService.Insert
Dim constr As String = ConfigurationManager.ConnectionStrings ("constr"). ConnectionString
Using con As New SqlConnection (constr)
Using cmd As New SqlCommand ("INSERT INTO Customers (Name, Country) VALUES (@Name, @Country)")
cmd.Parameters.AddWithValue ("@ Name", name)
cmd.Parameters.AddWithValue ("@ Country", country)
cmd.Connection = con
con.Open ()
cmd.ExecuteNonQuery ()
con.Close ()
End Using
End Using
End Sub