Click here to Skip to main content
15,794,202 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: How can my app look the same on all machines? Pin
Dave Kreskowiak10-Dec-19 5:59
mveDave Kreskowiak10-Dec-19 5:59 
AnswerRe: How can my app look the same on all machines? Pin
Gerry Schmitz10-Dec-19 9:14
mveGerry Schmitz10-Dec-19 9:14 
QuestionHow can I get an free installer that registers .dll and .ocx components as I install my app? Pin
Member 146743679-Dec-19 15:17
Member 146743679-Dec-19 15:17 
AnswerRe: How can I get an free installer that registers .dll and .ocx components as I install my app? Pin
CHill6010-Dec-19 2:44
mveCHill6010-Dec-19 2:44 
AnswerRe: How can I get an free installer that registers .dll and .ocx components as I install my app? Pin
gvidali7-Feb-20 4:09
gvidali7-Feb-20 4:09 
Question[Solved] - How to retrieve value inserted to variable Pin
nrdroque6-Dec-19 0:26
nrdroque6-Dec-19 0:26 
AnswerRe: How to retrieve value inserted to variable Pin
dan!sh 6-Dec-19 1:41
professional dan!sh 6-Dec-19 1:41 
AnswerRe: How to retrieve value inserted to variable Pin
Richard Deeming6-Dec-19 2:05
mveRichard Deeming6-Dec-19 2:05 
Member 14668666 wrote:
VB.NET
serialnumber = sql_query.ExecuteScalar()

Try
    If sql_query.ExecuteScalar() <> 0 Then
NB: You're executing the INSERT query twice every time you call this method.

Also, ExecuteScalar won't have anything to return, since your query doesn't return any records.

Add an OUTPUT clause[^] to your query:
VB.NET
sql_query.CommandText = "INSERT INTO etiquetas WITH (tablockx) (nome_posto, data, lote, serialnumber, partnumber, versao, indexnumber, semana, qrgerado, operador, snpn, posx, posy, impressora) OUTPUT inserted.serialnumber SELECT TOP (1) @posto, @data, @lote, T.x, @partnumber, @versao, @indexnumber, @semana, T.x + @partnumber + @versao + @indexnumber + @semana, @operador, T.x + @partnumber, @posx, @posy, @ip_impressora FROM [etiquetas] x CROSS APPLY (VALUES(format(convert(int, x.serialnumber) + 1, '0000000'))) T(x) WHERE partnumber LIKE @partnumber ORDER BY id DESC;"
Remove the @sn parameter, since it's not used in the query.

Change your code so that it only executes the query once.
VB.NET
' Remove this line:
' sql_query.Parameters.AddWithValue("@sn", serialnumber)

' Remove this line:
' serialnumber = sql_query.ExecuteScalar()

Try
    serialnumber = sql_query.ExecuteScalar()
Catch ex As Exception
    IO.File.AppendAllText("C:\ti\Log.txt", String.Format("{0}{1}", Environment.NewLine, Now() + " - " + ex.ToString()))
End Try




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: How to retrieve value inserted to variable Pin
nrdroque6-Dec-19 4:40
nrdroque6-Dec-19 4:40 
GeneralRe: How to retrieve value inserted to variable Pin
Eddy Vluggen6-Dec-19 9:49
professionalEddy Vluggen6-Dec-19 9:49 
QuestionMS Chart is adding extra X axis when doing multiple series. Pin
Member 1435926026-Nov-19 9:31
Member 1435926026-Nov-19 9:31 
QuestionHow to determine specific object from Msg.HWnd 'MESSAGE CLOSED' Pin
mo149225-Nov-19 3:32
mo149225-Nov-19 3:32 
QuestionMessage Closed Pin
17-Nov-19 21:37
professionalMorgan Lang17-Nov-19 21:37 
AnswerRe: can not find the pin Pin
Richard MacCutchan17-Nov-19 22:17
mveRichard MacCutchan17-Nov-19 22:17 
Questiongroup by name for sum amount Pin
Member 1332257413-Nov-19 20:39
Member 1332257413-Nov-19 20:39 
AnswerRe: group by name for sum amount Pin
Dave Kreskowiak14-Nov-19 3:40
mveDave Kreskowiak14-Nov-19 3:40 
Questioncode project data base Pin
abuahmed20191-Nov-19 5:24
abuahmed20191-Nov-19 5:24 
AnswerRe: code project data base Pin
Dave Kreskowiak1-Nov-19 6:00
mveDave Kreskowiak1-Nov-19 6:00 
QuestionSystem.IO.IOException HResult=0x80131620 When using NetworkStream.Read function Pin
fd975029-Oct-19 23:48
professionalfd975029-Oct-19 23:48 
AnswerRe: System.IO.IOException HResult=0x80131620 When using NetworkStream.Read function Pin
Richard MacCutchan30-Oct-19 0:09
mveRichard MacCutchan30-Oct-19 0:09 
GeneralRe: System.IO.IOException HResult=0x80131620 When using NetworkStream.Read function Pin
fd975030-Oct-19 0:23
professionalfd975030-Oct-19 0:23 
GeneralRe: System.IO.IOException HResult=0x80131620 When using NetworkStream.Read function Pin
fd975030-Oct-19 1:02
professionalfd975030-Oct-19 1:02 
QuestionHow to solve problem with datagrid and tabcontrol(vb.net) Pin
Member 1447080727-Oct-19 23:52
Member 1447080727-Oct-19 23:52 
AnswerRe: How to solve problem with datagrid and tabcontrol(vb.net) Pin
Richard MacCutchan28-Oct-19 0:14
mveRichard MacCutchan28-Oct-19 0:14 
GeneralRe: How to solve problem with datagrid and tabcontrol(vb.net) Pin
Member 1447080730-Oct-19 18:33
Member 1447080730-Oct-19 18:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.