Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone as of now this is my code Ive done..

Dim SqlconnectionString As String = "Data Source=192.168.0.4;Initial Catalog=CYBERYA;Persist Security Info=True;User ID=cyberya;Password=Piso4minutes;MultipleActiveResultSets=True"

Using con As New SqlClient.SqlConnection(SqlconnectionString)

Dim adapter As New SqlClient.SqlDataAdapter()
adapter.InsertCommand = cmd

'--Update the original SQL table from the datatable
Dim iRowsInserted As Int64 = _
adapter.Update(dt)

End Using


Dim myconnect2 As New SqlClient.SqlConnection
myconnect2.ConnectionString = "Data Source=192.168.0.4;Initial Catalog=CYBERYA;Persist Security Info=True;User ID=cyberya;Password=Piso4minutes;MultipleActiveResultSets=True"

Try
mycommand.ExecuteNonQuery()
Catch ex As System.Data.SqlClient.SqlException
MsgBox(ex.Message)
End Try
myconnect2.Close()
MsgBox("Success")
End Sub


yet there's an error quoted: ExecuteNonQuery: Connection property has not been initialized.

in which

Line 233:
Line 234: Try
Line 235: mycommand.ExecuteNonQuery()
Line 236: Catch ex As System.Data.SqlClient.SqlException
Line 237: MsgBox(ex.Message)


i already declare my sqlconnection so i need your help here why this error comes out thanks in advance
Posted
Updated 5-Jun-13 16:16pm
v2
Comments
ZurdoDev 5-Jun-13 22:13pm    
It's hard to read your code. You should click "Improve question" and add code tags. You need to set the Connection property on your SqlCommand.
[no name] 5-Jun-13 22:19pm    
It means exactly what it says. You created mycommand but never associate any connection object to it. Look at your first bit of code and compare it to the second bit of code.
Member 10033107 5-Jun-13 22:20pm    
so can you give any links or samples for that thing so i will fix that?? thanks for your response guys..
[no name] 5-Jun-13 22:22pm    
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.aspx

You create the connection, but you never .Open() it...
 
Share this answer
 
Comments
Member 10033107 5-Jun-13 22:18pm    
ooh so how is thet like conn.open??

i already did that with this command so i was wondering why is that happen with the error

Dim mycommand As SqlClient.SqlCommand = New SqlClient.SqlCommand()
mycommand.CommandText = "INSERT INTO tblsummaryImport ([id],[status],[SRN],[SrCode],[SrNumber],[CustomerName],[HomeContact],[BusinessContact],[MobileContact],[LotHouseNo],[RoomUnitStall],[BldgFloor],[BldgName],[Street],[Subdivision],[Barangay],[CityMunicipality],[Province],[Region],[Package],[PromoCode],[PaymentType],[ApplicationDate],[Endorseddate],[loanstatus],[PaymentDate],[ScheduleDate],[ActivationDate],[PCDelivery],[No.PCAvailed],[DatePCPickedUp],[SalesAgent],[Coordinator],[SalesChannel],[Salesgroup],[createdby],[timestamp]) Values(@id,@status,@srn,@customername,@homecontact,@businesscontact,@mobilecontact,@lothouseno,@roomunitstall,@bldgfloor,@bldgname,@street,@subdivision,@barangay,@citymunicipality,@province,@region,@package,@promocode,@loanstatus,@application,@paymenttype,@scheduledate,@activationdate,@pcdelivery,@nopcavailable,@datepcpickup,@salesagent,@salesgroup,@createdby,@timestamp)"
myconnect2.Open()
[no name] 5-Jun-13 22:20pm    
It's there but hard to read in the unformatted code "myconnect2.Open()".
Member 10033107 5-Jun-13 22:22pm    
so what will id o or alternative command i will write?? it so unusual to see this because i already stated it O.o help..guys!! im almost near to finish this ^^
Sorry, I didn't see the open...

Instead of creating the command directly, use the SqlConnection.CreateCommand, which automatically associates the connection with the command.

C#
SqlCommand myCommand = myconnect2.CreateCommand();
myCommand.CommandText = sql;
 
Share this answer
 
v2
Comments
Member 10033107 5-Jun-13 22:35pm    
ron i already did what youve said to check open(); yet it works as well but an error calls out like this :Failed to convert parameter value from a String to a Int64.
Member 10033107 5-Jun-13 22:36pm    
this is the code ive been working on

Dim strSql As String = "INSERT INTO tblsummaryImport ([id],[status],[SRN],[SrCode],[SrNumber],[CustomerName],[HomeContact],[BusinessContact],[MobileContact],[LotHouseNo],[RoomUnitStall],[BldgFloor],[BldgName],[Street],[Subdivision],[Barangay],[CityMunicipality],[Province],[Region],[Package],[PromoCode],[PaymentType],[ApplicationDate],[Endorseddate],[loanstatus],[PaymentDate],[ScheduleDate],[ActivationDate],[PCDelivery],[No.PCAvailed],[DatePCPickedUp],[SalesAgent],[Coordinator],[SalesChannel],[Salesgroup],[createdby],[timestamp]) Values(@id,@status,@srn,@customername,@homecontact,@businesscontact,@mobilecontact,@lothouseno,@roomunitstall,@bldgfloor,@bldgname,@street,@subdivision,@barangay,@citymunicipality,@province,@region,@package,@promocode,@loanstatus,@application,@paymenttype,@scheduledate,@activationdate,@pcdelivery,@nopcavailable,@datepcpickup,@salesagent,@salesgroup,@createdby,@timestamp)"


Dim SqlconnectionString As String = "Data Source=192.168.0.4;Initial Catalog=CYBERYA;Persist Security Info=True;User ID=cyberya;Password=Piso4minutes;MultipleActiveResultSets=True"

Using con As New SqlClient.SqlConnection(SqlconnectionString)

Dim cmd As New SqlClient.SqlCommand("Populatecsv", con) ' create command objects and add parameters
With cmd.Parameters
.Add("@id", SqlDbType.BigInt)
cmd.Parameters("@id").Value = ID
.Add("@srn", SqlDbType.VarChar, 50)
.Add("@srcode", SqlDbType.VarChar, 50)
.Add("@srnumber", SqlDbType.VarChar, 50)
.Add("@status", SqlDbType.VarChar, 500)
.Add("@CustomerName", SqlDbType.VarChar, 500)
.Add("@HomeContact", SqlDbType.VarChar, 500)
.Add("@BusinessContact", SqlDbType.VarChar, 500)
.Add("@MobileContact", SqlDbType.VarChar, 500)
.Add("@LotHouseNo", SqlDbType.VarChar, 500)
.Add("@RoomUnitStall", SqlDbType.VarChar, 500)
.Add("@BldgFloor", SqlDbType.VarChar, 500)
.Add("@BldgName", SqlDbType.VarChar, 500)
.Add("@Street", SqlDbType.VarChar, 500)
.Add("@Subdivision", SqlDbType.VarChar, 500)
.Add("@Barangay", SqlDbType.VarChar, 500)
.Add("@CityMunicipality", SqlDbType.VarChar, 500)
.Add("@Province", SqlDbType.VarChar, 500)
.Add("@Region", SqlDbType.VarChar, 500)
.Add("@Package", SqlDbType.VarChar, 500)
.Add("@PromoCode", SqlDbType.VarChar, 500)
.Add("@ApplicationDate", SqlDbType.DateTime)
.Add("@PaymentDate", SqlDbType.DateTime)
.Add("@EndorsedDate", SqlDbType.DateTime)
.Add("@PaymentDate", SqlDbType.DateTime)
.Add("@ScheduleDate", SqlDbType.DateTime)
.Add("@ActivationDate", SqlDbType.DateTime)
.Add("@PCDelivery", SqlDbType.VarChar, 500)
.Add("@NoPCAvailable", SqlDbType.VarChar, 50)
.Add("@DatePCPickUp", SqlDbType.DateTime)
.Add("@SalesAgent", SqlDbType.VarChar, 500)
.Add("@Coordinator", SqlDbType.VarChar, 500)
.Add("@SalesChannel", SqlDbType.VarChar, 500)
.Add("@SalesGroup", SqlDbType.VarChar, 500)
.Add("@CreatedBy", SqlDbType.VarChar, 500)
.Add("@loanStatus", SqlDbType.VarChar, 500)
.Add("@timestamp", SqlDbType.DateTime)
End With
con.Open()

Dim adapter As New SqlClient.SqlDataAdapter()
adapter.InsertCommand = cmd

'--Update the original SQL table from the datatable
Dim iRowsInserted As Int64 = _
adapter.Update(dt)
Try
cmd.ExecuteNonQuery()
Catch ex As System.Data.SqlClient.SqlException
Msg
hey guys im almost there having an error : "Failed to convert parameter value from a String to a Int64."

this what ive change with your advice guys:

Using con As New SqlClient.SqlConnection(SqlconnectionString)

Dim cmd As New SqlClient.SqlCommand("Populatecsv", con) ' create command objects and add parameters
With cmd.Parameters
.Add("@id", SqlDbType.BigInt)
cmd.Parameters("@id").Value = ID
.Add("@srn", SqlDbType.VarChar, 50)
.Add("@srcode", SqlDbType.VarChar, 50)
.Add("@srnumber", SqlDbType.VarChar, 50)
.Add("@status", SqlDbType.VarChar, 500)
.Add("@CustomerName", SqlDbType.VarChar, 500)
.Add("@HomeContact", SqlDbType.VarChar, 500)
.Add("@BusinessContact", SqlDbType.VarChar, 500)
.Add("@MobileContact", SqlDbType.VarChar, 500)
.Add("@LotHouseNo", SqlDbType.VarChar, 500)
.Add("@RoomUnitStall", SqlDbType.VarChar, 500)
.Add("@BldgFloor", SqlDbType.VarChar, 500)
.Add("@BldgName", SqlDbType.VarChar, 500)
.Add("@Street", SqlDbType.VarChar, 500)
.Add("@Subdivision", SqlDbType.VarChar, 500)
.Add("@Barangay", SqlDbType.VarChar, 500)
.Add("@CityMunicipality", SqlDbType.VarChar, 500)
.Add("@Province", SqlDbType.VarChar, 500)
.Add("@Region", SqlDbType.VarChar, 500)
.Add("@Package", SqlDbType.VarChar, 500)
.Add("@PromoCode", SqlDbType.VarChar, 500)
.Add("@ApplicationDate", SqlDbType.DateTime)
.Add("@PaymentDate", SqlDbType.DateTime)
.Add("@EndorsedDate", SqlDbType.DateTime)
.Add("@PaymentDate", SqlDbType.DateTime)
.Add("@ScheduleDate", SqlDbType.DateTime)
.Add("@ActivationDate", SqlDbType.DateTime)
.Add("@PCDelivery", SqlDbType.VarChar, 500)
.Add("@NoPCAvailable", SqlDbType.VarChar, 50)
.Add("@DatePCPickUp", SqlDbType.DateTime)
.Add("@SalesAgent", SqlDbType.VarChar, 500)
.Add("@Coordinator", SqlDbType.VarChar, 500)
.Add("@SalesChannel", SqlDbType.VarChar, 500)
.Add("@SalesGroup", SqlDbType.VarChar, 500)
.Add("@CreatedBy", SqlDbType.VarChar, 500)
.Add("@loanStatus", SqlDbType.VarChar, 500)
.Add("@timestamp", SqlDbType.DateTime)
End With
con.Open()

Dim adapter As New SqlClient.SqlDataAdapter()
adapter.InsertCommand = cmd

'--Update the original SQL table from the datatable
Dim iRowsInserted As Int64 = _
adapter.Update(dt)
Try
cmd.ExecuteNonQuery()
Catch ex As System.Data.SqlClient.SqlException
MsgBox(ex.Message)
End Try
con.Close()
MsgBox("Success")
End Using
 
Share this answer
 
v2
Comments
[no name] 5-Jun-13 22:40pm    
First, this is not an answer to the question.
Second, this is a totally different problem/question
Third, get rid of all of these "Add"s and use AddWithValue
Fourth, somewhere you are trying to convert a string to an int. Where that is, is a guess since you do not say. Likely candidates are "srn", "srcode", and "srnumber"
Member 10033107 5-Jun-13 22:48pm    
yes i already did sir

i suppose to type done here as a guide so in your thought it was a mistake .. im sorry
yet im trying already to figure out what do i need to adjust to fix the error Failed to convert parameter value from a String to a Int64. i believe i need to declare convertint64 to srn, srcode and srnumber?? as ive change to call already "id" so that my command will focus on one int..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900