2 Replies - 2198 Views - Last Post: 15 June 2009 - 06:30 AM Rate Topic: -----

#1 Albarada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-May 09

Insert into a Database in asp.net 2008

Post icon  Posted 14 June 2009 - 12:13 PM

hello, am trying to insert some values in my database ("Company"). here is my code:
		Dim NonQuery As String

		Dim sqlCon As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

		NonQuery = "Insert into messages(cname,ccity,ccountry,ccom,cphone,cmail) values ('" _
		& TxtName.Text.Trim & "','" & TxtCity.Text.Trim & "','" & TxtCountry.Text & "','" _
		& TxtComments.Text.Trim & "','" & TxtTell.Text.Trim & "','" & TxtEmail.Text.Trim & "');"

		Dim sqlCmd As New SqlCommand(NonQuery, sqlCon)
		sqlCon.Open()
		sqlCmd.ExecuteNonQuery()
		sqlCon.Close()



the code keeps giving an error message saying "Invalid object name 'messages'." while running (debugging) exactly on the " sqlCmd.ExecuteNonQuery()" line. Does anyone have any idea? please answer me asap...

Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: Insert into a Database in asp.net 2008

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1658
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Insert into a Database in asp.net 2008

Posted 14 June 2009 - 12:16 PM

That error message is saying that it cannot find a table named messages. Make sure you have the table name spelled correctly
Was This Post Helpful? 1
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Insert into a Database in asp.net 2008

Posted 15 June 2009 - 06:30 AM

put a breakpoint at

"Dim sqlCmd As New SqlCommand(NonQuery, sqlCon)"

then take the string from "NonQuery" and paste it into a SQL Server query window. See if it runs.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1