Hi I am having a problem storing image to mssql server I tried both Memory stream and BLOB as well and in both scinarios I get the same error "cannot insert the value null into image column msg 515 level 16 state 2 line 1", any suggestion is more than welcome Thanks.
Dim sqlstring = " begin tran;"
sqlstring &= " INSERT INTO tbl_customers (stnname, cardnum,
family_name, city, fam_mem_nu, id_num, mrkz_num) VALUES
('" & stn & "','" & cd & "', '" & fmnm & "','" & ct & "', '"
& fnum & "', '" & idn & "', '" & cntr & "')"
sqlstring &= "INSERT INTO tbl_customers(imag) SELECT * FROM
OPENROWSET(BULK N'c:\temp\tempimg', SINGLE_BLOB) imag ; "
sqlstring &= "commit tran;"
sql.CommandText = sqlstring
sql.Connection = conn
conn.Open()
Dim ms As New MemoryStream
img = CameraControl1.SnapshotSourceImage
img.Save("c:\temp\tempimg", Imaging.ImageFormat.Png)
'CameraControl1.SnapshotSourceImage.Save(ms, Imaging.ImageFormat.Bmp)
' PictureBox3.Image.Save(ms, PictureBox3.Image.RawFormat)
' ms.ToArray()
' Dim data As Byte() = ms.GetBuffer()
' Dim p As New SqlClient.SqlParameter("#img", SqlDbType.VarBinary)
' p.Value = data
' sql.Parameters.Add(p)
Dim x As Integer = sql.ExecuteNonQuery
Related
This is the last problem I have to face in for my capstone project, and it's driving me nuts.
Basically, I have to be able to identify if Section/Faculty/Room are all in use when scheduling a subject, to avoid conflicts.
Here's what I've worked on, but so far it can only detect when Room is in use.
I can't figure out how to be able to prevent scheduling that's in-between time periods. For example: First entry would be 7-8:30AM. Second entry would be 7:30 AM to 9 AM. With the former existing, it should reject the latter but I can't figure out how to do that. This is what I've cooked up so far. How would you guys go about this?
Public Function DataInUse() As Boolean
Dim Temp As Boolean
Temp = False
If FacultyInUse() = True Then
MessageBox.Show("Faculty in use.")
cboFaculty.Focus()
DisplayFacultyInUse()
DisplayLabelConflictForFaculty()
Temp = True
ElseIf RoomInUse() = True Then
MessageBox.Show("Room in use.")
cboRoom.Focus()
DisplayRoomInUse()
DisplayLabelConflictForRoom()
Temp = True
End If
Return Temp
End Function
Public Function FacultyInUse() As Boolean
Dim com As New OleDbCommand(" Select * from qrySubjectOfferring Where cTimeIn >=#" & cboFrom.Text & "# and cTimeOut <=#" & cboTo.Text & "# and Faculty like'" & cboFaculty.Text & "%' and cDay Like '%" & cboDay.Text & "%'", clsCon.con)
Dim dr As OleDbDataReader = com.ExecuteReader()
dr.Read()
If dr.HasRows Then
Return True
Else
Return False
End If
End Function
Public Function RoomInUse() As Boolean
Dim com As New OleDbCommand("Select * from qryRoomAvailability WHERE (cTimeIn <=#" & cboFrom.Text & "# AND cTimeOut >=#" & cboFrom.Text & "# AND Room = '" & cboRoom.Text & "' AND cDay = '" & cboDay.Text & "') OR (cTimeIn <=#" & cboTo.Text & "# AND cTimeOut >=#" & cboTo.Text & "# AND Room = '" & cboRoom.Text & "' AND cDay = '" & cboDay.Text & "') OR (cTimeIn >= #" & cboFrom.Text & "# AND cTimeOut <= #" & cboTo.Text & "# AND Room = '" & cboRoom.Text & "' AND cDay = '" & cboDay.Text & "') ", clsCon.con)
Dim dr As OleDbDataReader = com.ExecuteReader()
dr.Read()
If dr.HasRows Then
Return True
Else
Return False
End If
End Function
Public Function SubjectAlreadyOffered(sSubject As String) As Boolean
Dim com As New OleDbCommand("Select * from qrySubjectOfferring Where Subject LIKE '%" & sSubject & "%'", clsCon.con)
Dim dr As OleDbDataReader = com.ExecuteReader()
dr.Read()
If dr.HasRows Then
Return True
Else
Return False
End If
End Function
Try simplifying your SQL to use Between clause and eliminate all entries where the From or To are in existing entries
In your RoomInUse() function
Dim strSQL as String
strSQL = "SELECT * FROM qryRoomAvailability WHERE " & _
" Room = '" & cboRoom.Text & "' AND cDay = '" & cboDay.Text & "'" & _
" AND NOT (#" & cboFrom.Text "# BETWEEN [" & cTimeIn & "] AND [" & cTimeOut & "])" & _
" AND NOT (#" & cboTo.Text "# BETWEEN [" & cTimeIn & "] AND [" & cTimeOut & "])"
Dim com As New OleDbCommand(strSQL, clsCon.con)
I have two recordset which want to update one of them by value of the other. I did like this
stSql = "SELECT dbo.tblCableProperty.CatalogCode FROM dbo.tblCable INNER JOIN " & _
" dbo.tblCableProperty ON dbo.tblCable.CablePcode = dbo.tblCableProperty.CablePcode" & _
" WHERE dbo.tblCable.prjsubcode=" & prjsubcode & " AND dbo.tblCable.Active=1 " & " And dbo.tblCable.Gtag='" & Gtag & "' And dbo.tblCable.TagNo=" & tagno & " And dbo.tblCable.NTag=" & NTag & " And dbo.tblCable.EndStr='" & EndStr & "'"
rs.Open stSql, cn, adOpenStatic, adLockOptimistic
catalogCode = rs!catalogCode
rs.Close
stSql = "SELECT *,'' as ShowNum FROM viwShowNum WHERE prjsubcode=" & prjsubcode & " AND Active=1 " & " And Gtag='" & Gtag & "' And TagNo=" & tagno & " And NTag=" & NTag & " And EndStr='" & EndStr & "' ORDER BY 8"
rs.Open stSql, cn, adOpenDynamic, adLockOptimistic
rs.MoveFirst
stSql = "Select * from tblCoreCode where CatalogCode=" & catalogCode
Set rsCoreCode = New ADODB.Recordset
rsCoreCode.CursorLocation = adUseClient
rsCoreCode.Open stSql, cn, adOpenStatic, adLockOptimistic
While Not rs.EOF
criteria = "RealNum='" & rs!CoreNo & "'"
rsCoreCode.Filter = criteria
rs!ShowNum = CStr(rsCoreCode!ShowNum)
rsCoreCode.Filter = adFilterNone
rs.MoveNext
Wend
I get the following error on this part
rs!ShowNum = CStr(rsCoreCode!ShowNum)
multiple-step operation generated errors. check each status value
rsCoreCode!ShowNum is varchar(5). I tried to set the value
rs!ShowNum = "1"
but again I got the same error.
where is the problem?
Thank you
As asked in my comment, if rs.Updatable or rs!ShowNum.DataUpdatable are false, you can use this piece of code from Microsoft to retrieve an updatable RecordSet.
Same issue occurred to me the problem was that i violated an object property , in my case it was size the error came out as
"IntegrationException: Problem (Multiple-step operation generated errors. Check each status value.)"
Imports ADODB
Dim _RecordSet As Recordset
_rs.Fields.Append("Field_Name", DataTypeEnum.adVarChar, 50)
_Recordset("Field_Name").Value = _RecordDetails.Field_NameValue
_RecordDetails.Field_NameValue length was more than 50 chars , so this property was violated , hence the error occurred , so you should probably check if you didn't match one of the properties
I am getting this specific error, help would be appreciated
Microsoft VBScript runtime error '800a01a8'
Object required: 'openRecordSet(...)'
/admin/users/affiliates/process.asp, line 47
Line 47 is Set objRecordset = openRecordset(strSQL, objConnection)
<%
SetUserLevel(" 2 ")
If (InStr(Request.ServerVariables("HTTP_REFERER"), "://jim/admin/users/affiliate") = 0) Then
Response.Redirect( "/admin/users/affiliate/" )
End If
Dim objConnection, objRecordset, strSQL, Affiliate_ID
If (IsEmpty(Request.Form("Affiliate_ID")) Or RTrim(Request.Form("Affiliate_ID")) = "") Then
Affiliate_ID = 0
Else
Affiliate_ID = prepareSQL(Request.Form("Affiliate_ID"))
End If
strSQL = "EXEC sp_User_Add_Affiliate " & _
Session("User_ID") & ", '" & _
prepareSQL(Request.Form("First_Name")) & "', '" & _
prepareSQL(Request.Form("Middle_Initial")) & "', '" & _
prepareSQL(Request.Form("Last_Name")) & "', '" & _
prepareSQL(Request.Form("Email_Address")) & "', '" & _
Request.ServerVariables("REMOTE_ADDR") & "', " & _
Session.SessionID & ", '" & _
prepareSQL(Request.Form("Address_1")) & "', '" & _
prepareSQL(Request.Form("Address_2")) & "', '" & _
prepareSQL(Request.Form("City")) & "', '" & _
prepareSQL(Request.Form("State")) & "', '" & _
prepareSQL(Request.Form("Zip")) & "', '" & _
prepareSQL(Request.Form("Country")) & "', '" & _
prepareSQL(Request.Form("Phone")) & "', '" & _
prepareSQL(Request.Form("Phone_Extension")) & "', '" & _
prepareSQL(Request.Form("Fax")) & "', '" & _
prepareSQL(Request.Form("Company")) & "', '" & _
prepareSQL(Request.Form("Pay_To")) & "', '" & _
prepareSQL(Request.Form("Tax_ID")) & "', '" & _
prepareSQL(Request.Form("Tax_ID_Type")) & "', '" & _
prepareSQL(Request.Form("Tax_Class")) & "', " & _
Affiliate_ID & "," & _
Request.Form("ID") & "," & _
Request.Form("Approved")
Set objConnection = openConnectionAdmin()
Set objRecordset = openRecordset(strSQL, objConnection)
If objRecordset("Error") = "1" Then
Response.Write objRecordset("Data")
Response.End
End If
objRecordset.Close
Set objRecordset = Nothing
Set objConnection = Nothing
Response.Redirect ( "/admin/users/affiliates/" ) %>
Function openRecordSet(ByVal strSQL, ByRef objConnection)
On Error Resume Next
' logSQL(strSQL)
Set openRecordset = objConnection.Execute(strSQL)
If err.Number <> 0 Then
'Response.Write Err.Number & " - " & Err.Description logError("ASP: openRecordset: " & Err.Number & " - " & Err.Description & ": " & strSQL)
' Call displayErrorPage()
End If
End Function
The error typically is caused by using Set to indicate assignment of an object to a variable, but having a non-object for the right value:
>> Set v = New RegExp
>> [no news here are good news]
>> Set v = "a"
>>
Error Number: 424
Error Description: Object required
So check your openRecordset function. Does it return a recordset by executing
Set openRecordset = ....
(mark the Set) for the given parameters?
Update wrt comments:
This test script:
Option Explicit
' How to test the type of a function's return value that should
' be an object but sometimes isn't. You can't assign the return value
' to a variable because of VBScript's disgusting "Set".
WScript.Echo "TypeName(openConnectionAdmin()): ", TypeName(openConnectionAdmin())
WScript.Echo "TypeName(openRecordset(...)) : ", TypeName(openRecordset("", objConnection))
' Trying to create a connection and a recordset
Dim objConnection : Set objConnection = openConnectionAdmin()
Dim objRecordset : Set objRecordset = openRecordset("", objConnection)
Function openConnectionAdmin()
' Set openConnectionAdmin = CreateObject("ADODB.CONNECTION")
Set openConnectionAdmin = Nothing
End Function
' After removing the comments: Obviously this is a function that
' hides all errors; the programmer should be fed to the lions.
Function openRecordSet(ByVal strSQL, ByRef objConnection)
On Error Resume Next
Set openRecordset = objConnection.Execute(strSQL)
End Function
output:
TypeName(openConnectionAdmin()): Connection
TypeName(openRecordset(...)) : Empty
... Microsoft VBScript runtime error: Object required: 'openRecordset(...)'
or
TypeName(openConnectionAdmin()): Nothing
TypeName(openRecordset(...)) : Empty
... Microsoft VBScript runtime error: Object required: 'openRecordset(...)'
shows: By hiding every conceivable error in openRecordset() the function can return Empty (undetected!), which isn't an object and can't be assigned to a variable by using Set.
i have a drop down box , it has value that is retrieve from datasqlsource, however i want to get the count value on page load but it seem that it did not count
'Dim adapter As New SqlDataAdapter
'Dim ds As New DataSet
'Dim connectionString = ConfigurationManager.ConnectionStrings("myProject").ConnectionString
'Dim myConn As New SqlConnection(connectionString)
'Dim cmd = "SELECT * FROM Group Where groupID='" & DropDownList1.SelectedValue & "' AND customerID='" & Session("customerID") & "'"
'Try
' myConn5.Open()
' Dim myCmd5 As New SqlCommand(cmd5, myConn5)
' adapter.SelectCommand = myCmd5
' adapter.Fill(ds, "Group")
' ' txtQuan.Text = adapter.SelectCommand.ExecuteScalar().ToString()
' adapter.Dispose()
' myCmd5.Dispose()
' ' txtQuan.Text = ds.Tables(0).Rows.Count
' If ds.Tables(0).Rows.Count >= 10 Then
' lblNoPpl.Text = "The group is full"
' Else
' Dim numLefts As Integer = 10 - ds.Tables(0).Rows.Count
' lblNoPpl.Text = numLefts.ToString() + "space left"
'Catch ex As Exception
' MsgBox("Can not open connection ! ")
'End Try
if you use cmd.ExcuteScalar() method retrieve a count,the sql should be
SELECT COUNT(*) FROM Group Where groupID='" & DropDownList1.SelectedValue & "' AND customerID='" & Session("customerID") & "'"
In my vb6 I am getting error 3704 operation is not allowed when object is closed.
I have search stackoverflow for similar problem but I think I'm missing something. I need to update every row in vfp based from recordset rs1 Here my code:
Option Explicit
Dim cn As New ADODB.Connection
Dim cn1 As New ADODB.Connection
Private Sub trns_Click()
Set cn = New ADODB.Connection
Set cn1 = New ADODB.Connection
cn.ConnectionString = MDI1.txtcn.Text
cn.Open
cn1.ConnectionString = "Provider=VFPOLEDB;Data Source=\\host1\software\MIL\company0"
cn1.Open
rs1.Open "Select * from trans", cn, adOpenStatic, adLockPessimistic
Do While Not rs2.EOF
rs2.Open "update transac set no_ot_1_5 = " & rs1.Fields("ovt1") & ", no_ot_2_0 = " & rs1.Fields("ovt2") & ", no_ot_3_0" _
& "= " & rs1.Fields("ovt3") & ",Meal_allw = " & rs1.Fields("meal_allow") & ",on_duty = " & rs1.Fields("cnt") & ",no_d_local = " & rs1.Fields("local") & ",no_d_sick" _
& "= " & rs1.Fields("sick") & ",no_d_abs = " & rs1.Fields("absence") & ",no_d_spc = " & rs1.Fields("special") & ",Revenue02" _
& "= " & rs1.Fields("refund") & ",Revenue05 = " & rs1.Fields("prepay") & ",Deduct05 = " & rs1.Fields("prepay") & ",Revenue01 = " & rs1.Fields("comm") & "where code = '" & rs1.Fields("emp_code") & "' and transac.date = CTOD('" & trans.txtend2 & "')", cn1, adOpenDynamic, adLockPessimistic
If Not rs2.EOF Then
rs2.MoveNext
End If
Loop
rs2.close
Update query doesn't return recordset, hence your rs2 is not opened.
You perform your loop on the wrong recordeset : I replaced the some of the rs2 with rs1 in your code.
Do While Not rs1.EOF
rs2.Open "update transac set no_ot_1_5 = " & rs1.Fields("ovt1") & ", no_ot_2_0 = " & rs1.Fields("ovt2") & ", no_ot_3_0" _
& "= " & rs1.Fields("ovt3") & ",Meal_allw = " & rs1.Fields("meal_allow") & ",on_duty = " & rs1.Fields("cnt") & ",no_d_local = " & rs1.Fields("local") & ",no_d_sick" _
& "= " & rs1.Fields("sick") & ",no_d_abs = " & rs1.Fields("absence") & ",no_d_spc = " & rs1.Fields("special") & ",Revenue02" _
& "= " & rs1.Fields("refund") & ",Revenue05 = " & rs1.Fields("prepay") & ",Deduct05 = " & rs1.Fields("prepay") & ",Revenue01 = " & rs1.Fields("comm") & "where code = '" & rs1.Fields("emp_code") & "' and transac.date = CTOD('" & trans.txtend2 & "')", cn1, adOpenDynamic, adLockPessimistic
If Not rs1.EOF Then
rs1.MoveNext
End If
Loop
rs1.close
You dont need to create a recordset to execute an update, insert or delete on the database. Just use the statement cn1.Execute YourSqlStatement where YourSqlStatement is the string you are passing on the rs2.Open instruction. The Execute method on the connection optionally accepts a byRef variable where you can get the number of records affected.
Example:
Dim nRecords As Integer
cn1.Execute "Update Table Set Field = Value Where AnotherField = SomeValue ", nRecords
MsgBox "Total Updated Records: " & Format(nRecords,"0")
try to open your rs2 before using if in the do while statement., or do it like this
rs2.open " blah blah blah "
Do Until rs2.eof
For Each fld In rs2.field
value_holder = fld.value
Next
rs2.movenext
Loop