1
Answer

Can't add info to database

nice_guy_eddy_uk

nice_guy_eddy_uk

19y
1.7k
1
Hi

I'm trying to add some data to my database using this code


SqlCommand cmd = new SqlCommand("sp_insertDelivery", conn);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@SlotID", "1");

cmd.Parameters.AddWithValue("@CustID", textBoxCustNo.Text);

cmd.Parameters.AddWithValue("DeliveryDate", dateTimePicker1.Value.Date.ToShortDateString());

cmd.Parameters.AddWithValue("Chilled", textBoxChilled.Text);

cmd.Parameters.AddWithValue("Frozen", textBoxFrozen.Text);

cmd.Parameters.AddWithValue("Ambient", textBoxAmbient.Text);

cmd.Parameters.AddWithValue("OrderDate", System.DateTime.Now);

cmd.Parameters.AddWithValue("Notes", textBoxNotes.Text);

cmd.Connection.Open();

try

{

int i = 0;

i = cmd.ExecuteNonQuery();

if (i >= 1)

{

toolStripStatusLabel1.Text = "Customer order has been made";

}

else

{

toolStripStatusLabel1.Text = "error";

}

}




The weird thing is that it says that data has been added successfully but when I check to see if it is there then it hasn't added it.
I can add data manually so I don't think there is anything wrong with the permissions.

Any help would be great. PS This is ado.net 2.0 

Answers (1)
0
saphiroth42

saphiroth42

NA 53 0 20y
It seems to work very well. I hope there will to no side affects from this. Thanks a lot.
0
vidhya_bala2003

vidhya_bala2003

NA 20 0 20y
Hi saphiroth, Actually i also had the same problem. My project is heavier, having more than 110 forms. I also in search of a solution for more than 1 month. i have tried various methods but in vain. At last i tried this mtd and i haven't experienced any performance degrade by using this method. Try out and tell if u face any problem. Chk out this url for more info http://addressof.com/blog/archive/2003/11/19/281.aspx
0
saphiroth42

saphiroth42

NA 53 0 20y
Again I want to say thanks. How did u find this method? Is it safe to use through out every form? What I did is make a new class and put that function in the class. So I create an instance of the class and call this function to clear out RAM. I hope this is ok to do.
0
saphiroth42

saphiroth42

NA 53 0 20y
nevermind, I read up on the SetProcessWorkingSetSize. Thank you for your help.
0
saphiroth42

saphiroth42

NA 53 0 20y
I don't clearly understand what this does or how it works. How does it help memory management?
0
vidhya_bala2003

vidhya_bala2003

NA 20 0 20y
Have you tried using the SetProcessWorkingSetSize Win32 API Function Form1.vb Private Sub Buttonopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frm2 As New Form2() frm2.MdiParent = Me frm2.Dock = DockStyle.Fill frm2.Show() frm2.BringToFront() End Sub Form2.vb Private Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal hProcess As IntPtr, ByVal dwMinimumWorkingSetSize As Int32, ByVal dwMaximumWorkingSetSize As Int32) As Int32 Public Function SaveMemory() As Int32 Return SetProcessWorkingSetSize(Diagnostics.Process.GetCurrentProcess.Handle, -1, -1) End Function 'Form Close Private Sub Buttonclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click SaveMemory() Me.Close() End Sub
0
MythicalMe

MythicalMe

NA 245 0 20y
Not necessarily. Garbage collection occurs when an object tries to allocate memory for a new object and the heap has no free memory. So memory allocated may not be collected if the apllication doesn't create many objects. Further, it can take up to two collection cycles before an object's memory allocation is actually released back to the pool. When memory is collected the object's Finalize method is called, and then the collector frees the memory. If you need to get memory back to the heap faster you can call GC.Collect yourself. If you do so, you should follow it up with a GC.WaitForPendingFinalizers call. There is a slight performance hit in doing this.