Please look into the code and help me ...

dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "mr_no"
dbInsert.Parameters.Item("mr_no").Value = 1

dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "mr_date"
dbInsert.Parameters.Item("mr_date").Value = DateTimePicker1.Value

dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "item_code"
dbInsert.Parameters.Item("item_code").Value = txtItemcode.Text

dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "qty"
dbInsert.Parameters.Item("qty").Value = txtQty.Text

dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "mr_status"
dbInsert.Parameters.Item("mr_status").Value = "N"


dbInsert.CommandText = "insert into mr_head values ('MBBK7490','2',DateTimePicker1.VALUE,txt_itemcode.text,txtQty.text,'N',NULL);"

        dbInsert.CommandType = CommandType.Text
        dbInsert.Connection = connection
        dbInsert.ExecuteNonQuery()
        MsgBox("Saved")
        connection.Close()

The data is getting saved but some values are getting saved as date format.

Please check the data below

JOB_CODE : MBBK7490 (Correct)
MR_NO : 2 (CORRECT)
MR_DATE : 31-12-1899 (WRONG)
ITEM_CODE : MR_DATE (WRONG)
QTY : ITEMCODE (WRONG)
MR_STATUS : N (CORRECT)

Please help..

Vivek

hello !
your are using complicated code for insert, use this code

Try
            MyFields = "(SalesID,SalesDate)"
            MyValues = "(@SalesID,@SalesDate)"
            dim MyConn as new sqlconnection("connectionstring")
            MyConn.Open()
            Dim Mycmd As New SqlCommand
            Mycmd.Connection = MyConn
            Mycmd.CommandText = "insert into  table1  Values " & MyValues
            Mycmd.Parameters.Add("SalesID", SqlDbType.BigInt).Value = saleid
            Mycmd.Parameters.Add("SalesDate", SqlDbType.DateTime).Value = SaleDate
          
            Mycmd.ExecuteNonQuery()
            MyConn.Close()
            'Return 1
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try

And this will work fine at my end

Regards

hello !
your are using complicated code for insert, use this code

Try
            MyFields = "(SalesID,SalesDate)"
            MyValues = "(@SalesID,@SalesDate)"
            dim MyConn as new sqlconnection("connectionstring")
            MyConn.Open()
            Dim Mycmd As New SqlCommand
            Mycmd.Connection = MyConn
            Mycmd.CommandText = "insert into  table1  Values " & MyValues
            Mycmd.Parameters.Add("SalesID", SqlDbType.BigInt).Value = saleid
            Mycmd.Parameters.Add("SalesDate", SqlDbType.DateTime).Value = SaleDate
          
            Mycmd.ExecuteNonQuery()
            MyConn.Close()
            'Return 1
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try

And this will work fine at my end

Regards

Could u please explain "myvalues".. How do i pass values at runtime...

oh sorry :P here is complete code

sub MyInsert(byval salesid as integer , byval salesdate as datetime)
   Try
            MyFields = "(SalesID,SalesDate)"
            MyValues = "(@SalesID,@SalesDate)"
            dim MyConn as new sqlconnection("connectionstring")
            MyConn.Open()
            Dim Mycmd As New SqlCommand
            Mycmd.Connection = MyConn
            Mycmd.CommandText = "insert into  table1  Values " & MyValues
            Mycmd.Parameters.Add("SalesID", SqlDbType.BigInt).Value = saleid
            Mycmd.Parameters.Add("SalesDate", SqlDbType.DateTime).Value = SaleDate
'and you can directly provide textboxes values as a parameters like this
  Mycmd.Parameters.Add("SalesID", SqlDbType.BigInt).Value = val(txtsalesid.text)
            Mycmd.Parameters.Add("SalesDate", SqlDbType.DateTime).Value = datetimepicker.values.date
          
            Mycmd.ExecuteNonQuery()
            MyConn.Close()
            'Return 1
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try
end sub
'now where you call this sub you have to give two parameters like this
myinsert(val(txtsalesid.text),datetimepicker.value.date)

hope this time this will helps you :) if you like my ans please mark this thread solved :)

Can you change this code for access... Please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.