Please forgive me if I am overlooking something really obvious here, as I am totally new to programming. I have spent the last couple of days trying to troubleshoot an issue I have been having. Long story short, I have a CRM app that I am building that includes a database with four tables (Employee, Responses, Status and Table). I believe that my issue is with my connection string, but I am unsure of how to fix it. Per the database properties window, the connection string is as follows:
Data Source=(LocalDB)\v11.0;AttachDbFilename="C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf";Integrated Security=True
I am currently receiving the following error:
An unhandled exception of type 'System.InvalidOperationException' occurred in 349591.exe
Additional information: An error occurred creating the form. See Exception.InnerException for details. The error is: An expression of non-boolean type specified in a context where a condition is expected, near ','.
I have tried everything I know, and am stumped. Thank you for any help you can provide. Please find the DBUtil code I wrote below:
Imports System.Data
Imports System.Data.SqlClient
Public Class DButil
Public cs As String
Public Function GetDataView(ByVal sql As String) As DataView
Dim ds As New DataSet
Dim da As New SqlDataAdapter(sql, cs)
da.Fill(ds)
Dim dv As New DataView(ds.Tables(0))
Return dv
End Function
Public Sub New()
'cs = "Data Source=(LocalDB)\v11.0;"
'cs = "Data Source=(LocalDB)\v11.0;AttachDbFilename='C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf';Integrated Security=True"
'cs += "Integrated Security =True;"
' Dim strPath As String = Replace(System.AppDomain.CurrentDomain.BaseDirectory, "bin\debug\", "cms.mdf")
cs = ("Data Source=(LocalDB)\v11.0;AttachDbFilename='C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf';Integrated Security=True")
End Sub
Public Function SaveComplaint(
ByVal ComplaintID As Integer,
ByVal Description As String,
ByVal Proposal As String,
ByVal Location As String,
ByVal OpenDate As Object,
ByVal CloseDate As Object,
ByVal StatusID As Integer,
ByVal EmployeeID As Integer) As Boolean
OpenDate = Convert.ToDateTime(OpenDate)
If CloseDate.ToString.Length = 0 Then
CloseDate = DBNull.Value
Else
CloseDate = Convert.ToDateTime(CloseDate)
End If
Dim sql As String
If ComplaintID = 0 Then
sql = "INSERT INTO Complaints (Description, Proposal, Location, OpenDate, "
sql += "CloseDate, StatusID, EmployeeID) VALUES (@Description, @Proposal, "
sql += "@Location, @OpenDate, @CloseDate, @StatusID, @EmployeeID)"
Else
sql = "UPDATE Complaints SET Description=@Description, Proposal=@Proposal, Location=@Location, OpenDate=@OpenDate, "
sql += "CloseDate=@CloseDate, StatusID=@StatusID, EmployeeID=@EmployeeID WHERE ComplaintID=@ComplaintID"
End If
Dim cn As New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename='C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf';Integrated Security=True")
Dim cm As New SqlCommand(sql, cn)
Try
With cm.Parameters
.AddWithValue("@ComplaintID", ComplaintID).DbType = DbType.Int32
.AddWithValue("@Description", Description).DbType = DbType.String
.AddWithValue("@Proposal", Proposal).DbType = DbType.String
.AddWithValue("@Location", Location).DbType = DbType.String
.AddWithValue("@OpenDate", OpenDate).DbType = DbType.DateTime
.AddWithValue("@CloseDate", CloseDate).DbType = DbType.DateTime
.AddWithValue("@StatusId", StatusID).DbType = DbType.Int32
.AddWithValue("@EmployeeID", EmployeeID).DbType = DbType.Int32
End With
cn.Open()
cm.ExecuteNonQuery()
cn.Close()
Return True
Catch ex As Exception
MessageBox.Show(ex.Message, "Error in DBUtil.SaveComplaint",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function
Public Function RunSQL(ByVal sql As String) As Boolean
Dim cn As New SqlConnection(cs)
Dim cm As New SqlCommand(sql, cn)
Try
cn.Open()
cm.ExecuteNonQuery()
cn.Close()
Return True
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & sql, "Error in DBUtil.RunSQL", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function
End Class