Code to save to SQLServerCE

Code converted to save to SQLServerCE not working

Page 1 of 1

2 Replies - 1315 Views - Last Post: 18 May 2009 - 08:54 AM Rate Topic: -----

#1 cliffste   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 17-November 08

Code to save to SQLServerCE

Posted 17 May 2009 - 01:32 PM

This code saved to a SQLServer 2005 database before I converted it to save to a SQLServerCE database which it won’t do now. Does anyone know what I may have left out or did wrong in my covertion process?

 Private Sub btnenterSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnenterSave.Click
		Dim Prompt As String
		If Me.txtName.Text = Nothing Then
			Prompt = "You must enter a name in the textbox"
			MessageBox.Show(Prompt)
			Me.txtName.Focus()
			Exit Sub
		End If
		Dim Myname As String
		Myname = txtName.Text
		Dim cnSQL As SqlServerCe.SqlCeConnection
		Dim cmSQL As SqlServerCe.SqlCeCommand
		Dim drSQL As SqlServerCe.SqlCeDataReader
		Dim strSQL As String
		Myname = Me.txtName.Text
		strSQL = " SELECT * FROM [Names] WHERE Name LIKE('" & Myname & "') "
		cnSQL = New SqlServerCe.SqlCeConnection(GetConnection())
		cnSQL.Open()
		cmSQL = New SqlServerCe.SqlCeCommand(strSQL, cnSQL)
		drSQL = cmSQL.ExecuteReader()
		Try
			If drSQL.Read() Then
				Me.txtName.Text = drSQL.Item("Name").ToString()
				Prompt = "This name has already been entered"
				MessageBox.Show(Prompt)
				txtName.Text = ""
				txtName.Select()
				drSQL.Close()
				Exit Sub
			Else
				drSQL.Close()
				InsertMyData(connectionString, Myname)
			End If
		Catch ex As Exception
			MessageBox.Show(ex.Message & vbCrLf & ex.GetType().ToString() & "-One")
		End Try
		FillTotalNames()
		InsertTotalForms()
		frmTab.Show()
		Me.Hide()
	End Sub
	Public Sub InsertMyData(ByVal myConnectionString As String, ByVal name As String)
		Myname = txtName.Text
		Dim myInsertQuery As String = "INSERT INTO [Names] (Name) VALUES ('" & Myname & "')"
		Dim connection As New SqlServerCe.SqlCeConnection(GetConnection())
		Dim objCommand As New SqlServerCe.SqlCeCommand(myInsertQuery, connection)
		Dim retvalue As Integer
		Try
			connection.Open()
			retvalue = objCommand.ExecuteNonQuery()
		Catch ex As Exception
			MessageBox.Show(ex.Message & vbCrLf & ex.GetType().ToString() & "-One")
		End Try
		connection.Close()
		connection.Dispose()
		connection = Nothing
	End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Code to save to SQLServerCE

#2 noorahmad   User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Code to save to SQLServerCE

Posted 17 May 2009 - 10:00 PM

can you past the Error
Was This Post Helpful? 0
  • +
  • -

#3 cliffste   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 17-November 08

Re: Code to save to SQLServerCE

Posted 18 May 2009 - 08:54 AM

View Postnoorahmad, on 17 May, 2009 - 09:00 PM, said:

can you past the Error

No errors. program seems to work find but if you close and reopen there is nothing saved or if you check the database it is empty.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1