What's The Use Of Command Builder In Asp.net?

3

3 Answers

Zeshan Hayder Profile
Zeshan Hayder answered
Command builder generates insert/update/delete commands for data adapter based on select command. Automatic creation of insert/update/delete commands hinders performance. In case if we know the contents of insert/update/delete, then we should create these explicitly. It is much better to create explicit stored procedures for insert/update/delete and assign these. Store procedures are much better way to do and it is all the way safer than these.

The command builder uses select command property of data adapter to determine values for other commands. If there is change in select command of data adapter, remember to call refresh Scheme to update the command properties. Point here to be note able is that command builder will only generate a command for data adapter's command property if command property is null, if it is not null then it will not make.

By default command properties are null for data adapter, so whenever we use it we have to careful about it. If you explicitly set a command property, the command builder does not overwrite it. You need to set the command property to null to allow command builder to generate a command for command property. Another thing here is that command builder is nice to use and recommended if the tables are simple but when we are talking about complex select statements then we should give more parameters and new commands for each of the command properties in the data adapter.
Anonymous Profile
Anonymous answered
Override public void PostUserWallFromId(int id, int code, string post)
    {
  string statement = @"
INSERT INTO [UsersPost] ([SentId], [ToId], [Post], [Date])
VALUES (@sentid, @toid, @post, @date)";
  using (con = new SqlConnection(connStr))
  {
  SqlCommand cmd = new SqlCommand(statement, con);

  cmd.Parameters.AddWithValue("sentid", "2");
  cmd.Parameters.AddWithValue("toid", "3");
  cmd.Parameters.AddWithValue("post", post);
  cmd.Parameters.AddWithValue("date", DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Day.ToString());
  con.Open();
  cmd.ExecuteNonQuery();
  }
    }
Anonymous Profile
Anonymous answered
R6ty

Answer Question

Anonymous