0

How use Parameter.add with when i have two insert statements like below

structure table:

CREATE TABLE TAccount
(
    Username nchar(10), // Primary Key
    Password nchar(100),
    RolesId int // Foreign Key from table Role
);

CREATE TABLE TUser
(
    UserId nchar(10), // Primary Key & Foreign Key from table Account
    Name nchar(100),
    Birthday date,
    Address nchar(100) 
);

Model

//class user
public string UserId { get; set; }
public string Name { get; set; }
public string Birthday { get; set; }
public string Address { get; set; }

snippet code:

// method InsertUser(List<User> data)
comm.CommandText = "INSERT INTO TAccount (Username, Password, RolesID) VALUES (@UserId, @UserId, 4) " +
                   "INSERT INTO TUser (UserId, Name, Birthday, Address) VALUES (@UserId, @Name, @Birthday, @Address)";

// HOW TO GENERATE VALUE DATA TO QUERY?

comm.CommandType = CommandType.Text;
conn.Open();
comm.ExecuteNonQuery();
TheGameiswar
  • 27,855
  • 8
  • 56
  • 94
marshall
  • 74
  • 1
  • 7
  • What is "paramter list array" and what means "GENERATE VALUE DATA TO QUERY"? – Tim Schmelter Nov 28 '16 at 15:42
  • how to using parameter.Add and get value from prameter List data – marshall Nov 28 '16 at 15:43
  • @TimSchmelter if I'm correct, I think he wants to insert a list of user objects with 1 query. –  Nov 28 '16 at 15:47
  • 1
    Potentially answered (duplicate?) of http://stackoverflow.com/questions/2972974/how-should-i-multiple-insert-multiple-records... But indeed this question need some [edit] to clarify exact problem. – Alexei Levenkov Nov 28 '16 at 15:56

1 Answers1

3
 SqlParameter param = new SqlParameter("@Name", SqlDbType.NVarChar, 16);
 param.Value = "marshall";
 comm.Parameters.Add(param);
Owen Pauling
  • 11,349
  • 20
  • 53
  • 64