TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed elbarbary
NA
1.6k
277.8k
How to create function return statement insert into table v
Aug 12 2019 10:00 PM
Problem
How to return statement insert into table values from json file ?
I work on newton soft library and I try to insert data to table master_table
but my problem how to make function return insert statement as bellow :
insert
into
master_table(id,branch_id,
name
,address,phone)
values
(1,1,
"bar"
,
"fleet street"
,
"555"
)
table ,keys,fields content flexible or dynamic .
my jsonfile D:\\1.json as below :
{
"master"
: {
"table"
:
"master_table"
,
"fields"
: {
"name"
:
"bar"
,
"address"
:
"fleet street"
,
"phone"
:
"555"
},
"keys"
:{
"id"
: 1,
"branch_id"
: 1
}
}
}
I already make get keys and fields but cannot make concatenate
insert statement as result .
How to concatenate insert statement that have keys + fields
as statement on first thread .
public
static
ExpandoObject ToExpando(
string
json)
{
if
(
string
.IsNullOrEmpty(json))
return
null
;
return
(ExpandoObject)ToExpandoObject(JToken.Parse(json));
}
private
static
object
ToExpandoObject(JToken token)
{
switch
(token.Type)
{
case
JTokenType.Object:
var expando =
new
ExpandoObject();
var expandoDic = (IDictionary<
string
,
object
>)expando;
foreach
(var prop
in
token.Children<JProperty>())
expandoDic.Add(prop.Name, ToExpandoObject(prop.Value));
return
expando;
case
JTokenType.Array:
return
token.Select(ToExpandoObject).ToList();
default
:
return
((JValue)token).Value;
}
}
static
void
Main(
string
[] args)
{
string
JsonData = File.ReadAllText(
"D:\\1.json"
);
var ebj = SqlFactory.ToExpando (JsonData);
var name = (ebj
as
dynamic).master.table;
var fields = (ebj
as
dynamic).master.fields;
foreach
(dynamic i
in
fields)
{
string
key = i.Key;
object
value = i.Value;
}
var keys = (ebj
as
dynamic).master.keys;
}
Reply
Answers (
4
)
Message says valid database name ls invalid.
How implement GET and PUT API for updating two tables data