Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

insert existing json in db

$
0
0

Hi,

My code:

var obj = new
        {
            data = new
        {
            post_info = new
            {
                ID = "1",
                UserId = HttpContext.Current.Request.Cookies["UserId"],
                date = DateTime.Now,
                imgpath = "none",
                videopath = "none",
                likecount = "1",
                sharecount = "1",
                likeperson = new { ID= "likeperson1" },
            },



        }

        };
             var post = JsonConvert.SerializeObject(obj);


             string conStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
             using (SqlConnection con = new SqlConnection(conStr))
             {
                 using (SqlCommand cmd = new SqlCommand("INSERT INTO tbl_Posts VALUES(@Post)"))
                 {
                     cmd.CommandType = CommandType.Text;
                     cmd.Parameters.AddWithValue("@Post", post);
                     cmd.Connection = con;
                     con.Open();
                     cmd.ExecuteNonQuery();
                     con.Close();
                 }
             }


This code is on Button1 and insert correct.

In Button2 I need add another likeperson in db.  I need to find ID=1 and insert new likeperson:
likeperson = new { ID= "likeperson1" },
likeperson = new { ID= "likeperson2" }, - its new data-

Please help.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>