I have a problem while inserting records into SQL Server.
The string from C# doesn't show up in SQL Server as I'm inserting the sql just insert the first char
Example: If I insert 22222 in the data base just the first 2 inserted
Note I'm using a stored procedure for my first time.
This is my code:
public void insert_workshop(DateTime Pdate, string PTime, string PDesc, byte[] Img)
{
SqlCommand cmd = new SqlCommand("[InsertWorkShops]", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@WorkshopsDate", SqlDbType.Date).Value = Pdate;
cmd.Parameters.Add("@Time", SqlDbType.NVarChar).Value = PTime;
cmd.Parameters.Add("@WorkshopsDescription", SqlDbType.NVarChar).Value = PDesc;
cmd.Parameters.Add("@WorkshopsImage", SqlDbType.Image).Value = Img;
cmd.Parameters.Add("@CreatedBy", SqlDbType.NVarChar).Value = 1;
try
{
cmd.ExecuteNonQuery();
Msg = "Add Done ";
}
catch
{
Msg = "Error While Adding";
}
WorkShopTransactions Ws = new WorkShopTransactions();
Ws.insert_workshop(WorkShopDT.Value, txtWorshopTime.Text.ToString(),
txtWorkshopDescriptions.Text.ToString(), img);
T-SQL:
ALTER PROCEDURE [dbo].[InsertWorkShops]
@WorkshopsDate date,
@Time nvarchar,
@WorkshopsDescription nvarchar,
@WorkshopsImage image,
@CreatedBy int
AS
BEGIN
SET NOCOUNT ON;
insert into Workshops
values(@WorkshopsDate, @Time, @WorkshopsDescription, @WorkshopsImage, @CreatedBy)
END
imageis deprecated and why isn't time given atimedatatype?