View Single Post
  #4 (permalink)  
Old February 13th, 2012, 06:09 AM
akaas.website akaas.website is offline
Registered User
Points: 30, Level: 1
Points: 30, Level: 1 Points: 30, Level: 1 Points: 30, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default

give paramemeters names instead of "?"

like:

private void BuildCommands()
{
SqlConnection connection =
(SqlConnection)dataAdapter.SelectCommand.Connectio n;

// Declare a reusable insert command with parameters
dataAdapter.InsertCommand = connection.CreateCommand();
dataAdapter.InsertCommand.CommandText =
"insert into Computer " +
"(Id, Name) " +
"values " +
"(@ID, @Name)";
dataAdapter.InsertCommand.Parameters.Add("@ID", SqlDbType.NVarChar, 16, "Id");
dataAdapter.InsertCommand.Parameters.Add("@Name", SqlDbType.NVarChar, 16, "Name");

// Declare a reusable update command with parameters
dataAdapter.UpdateCommand = connection.CreateCommand();
dataAdapter.UpdateCommand.CommandText = "update Computer " +
"set Name = @Name" +
"where Id = @ID ";
dataAdapter.UpdateCommand.Parameters.Add("@Name", SqlDbType.Char, 0, "Name");
dataAdapter.UpdateCommand.Parameters.Add("@Id", SqlDbType.Char, 0, "Id");



/*SqlCommand command = connection.CreateCommand();
command.CommandText = "Select * from Computer;";
connection.Open();

SqlDataReader reader = command.ExecuteReader();

while (reader.Read())
{
Console.WriteLine("\t{0}\t{1}",
reader[0], reader[1]);
}
reader.Close();*/

}



Regards,
Akaas Developer
http://www.questions-interviews.com/...hnologies.aspx
Reply With Quote