Berikut beberapa penjelasannya:
perbedaan antara perintah Add dan AddWithValue
Dim cmd as new SqlCommand("SELECT * FROM MyTable WHERE MyDate>@TheDate",conn)
cmd.Parameters.Add("@TheDate",SqlDbType.DateTime).Value="2/1/2007"
vs
cmd.Parameters.AddWithValue("@TheDate","2/1/2007")
"Tambah memaksa konversi dari string ke tanggal saat masuk ke parameter. AddWithValue hanya akan meneruskan string ke SQL Server.
- http://msdn. microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx
- http://msdn.microsoft.com/en-us/ perpustakaan/yy6y35y8.aspx
Sunting :
contoh untuk mendapatkan Output-Parameter:
C#
cmd.Parameters.Add(new SqlParameter("@TheNewId", SqlDbType.Int, int.MaxValue));
cmd.Parameters("@TheNewId").Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
int theNewID = (int)cmd.Parameters("@TheNewId").Value;
VB.Net
cmd.Parameters.Add(New SqlParameter("@TheNewId", SqlDbType.Int, Int32.MaxValue))
cmd.Parameters("@TheNewId").Direction = ParameterDirection.Output
cmd.ExecuteNonQuery()
Dim theNewID As Int32 = DirectCast(cmd.Parameters("@TheNewId").Value, Int32)