-
Apr 15th, 2019, 08:09 AM
#1
Thread Starter
Member
-
Apr 15th, 2019, 08:53 AM
#2
Re: UPDATE image field with NULL value in VB.NET
If you just google "sql server set image null" ... you get back a lot of results.
https://www.google.com/search?q=sql+...set+image+null
-tg
-
Apr 15th, 2019, 08:54 AM
#3
Re: UPDATE image field with NULL value in VB.NET
We can't be sure without seeing your code, but there is a good chance that you want DBNull.Value
If that doesn't work for you, show us the relevant section of the code.
-
Apr 15th, 2019, 09:03 AM
#4
Re: UPDATE image field with NULL value in VB.NET
Yep.
vbnull.value how does this even compile?
Small basic sample:
Code:
Imports System.Data.SqlClient
Public Class Form1
Private connectionstring As String = "Data Source=Mydatasource\SQLEXPRESS;Initial Catalog=tests;Integrated Security=True;"
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim connection = New SqlConnection(connectionstring)
connection.Open()
Dim command As SqlCommand = New SqlCommand()
command.Connection = connection
command.CommandType = CommandType.Text
command.Parameters.Add("@im", SqlDbType.Image).Value = DBNull.Value
command.CommandText = "update mytable set imgx = @im"
Try
command.ExecuteNonQuery()
Catch ex As Exception
End Try
connection.Close()
End Sub
End Class
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 15th, 2019, 09:03 AM
#5
Thread Starter
Member
Re: UPDATE image field with NULL value in VB.NET
My code is :
VB.NET Code:
Connexion.Open() Dim Num_MET$ = Mid(Demande.Lab_Num_MET.Text, 8, 2) & Mid(Demande.Lab_Num_MET.Text, 11, 13) 'Récupère le Numéro MET Dim Rq As String = "UPDATE Donnees_MET SET PlanST = @File_Field WHERE Num_MET = '" & Num_MET & "'" Dim Cmd As New SqlCommand(Rq, Connexion) Cmd.Parameters.Add("@File_Field", SqlDbType.VarBinary, -1) Cmd.Parameters("@File_Field").Value = DBNull.Value Try Cmd.ExecuteNonQuery() Catch ex As Exception MsgBox(ex.Message & " Catégorie d'erreur N° 20") End Try Cmd.Dispose() Connexion.Close()
Sorry @tg, I looked before but I maybe have a vocabulary problem when I googled it.
I will try some things tomorrow and let you know soon (I let the thread open for now )
-
Apr 15th, 2019, 09:21 AM
#6
Re: UPDATE image field with NULL value in VB.NET
Have you read my code?
"SqlDbType.Image"
You also should not store images in the database unless there is some special reason or the images are very small or limited.
Store them in a folder and put the folder path or link in the database.
Also it's not good practice to use "$" or there signs in a variable unless in special cases . If you've asked me I would have thought that .net will project this as an exception but apparently it does not.... Ah it does when you set the variable type. Good, I was getting ready for a badmouth on .net
Last edited by sapator; Apr 15th, 2019 at 09:41 AM.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 16th, 2019, 01:41 AM
#7
Thread Starter
Member
Re: UPDATE image field with NULL value in VB.NET
Originally Posted by sapator
Have you read my code?
"SqlDbType.Image"
Yes I red it, but I put here my code which do not work without update, I will try your code this morning and let you know
Originally Posted by sapator
You also should not store images in the database unless there is some special reason or the images are very small or limited.
Store them in a folder and put the folder path or link in the database.
Thank you for the tip, if I could I prefer to convert image to binary(MAX) but I 'm afraid to loose data...
Originally Posted by sapator
Also it's not good practice to use "$" or there signs in a variable unless in special cases . If you've asked me I would have thought that .net will project this as an exception but apparently it does not.... Ah it does when you set the variable type. Good, I was getting ready for a badmouth on .net
Sorry but here you did a mistake, the "$" is not a part of a variable name, this is just to indicate that the variable "Num_MET" is a string.
VB.NET Code:
Dim Num_MET$ --> Dim Num_MET as string
(Just a time gain)
Originally Posted by sapator
Good, I was getting ready for a badmouth on .net
I didn't understood this sentence, could you explain it to me ?
Thank you !
-
Apr 16th, 2019, 02:09 AM
#8
Thread Starter
Member
Re: UPDATE image field with NULL value in VB.NET
Just replace SqlDbType.VarBinary by SqlDbType.Image works well for me, thank you all
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|