无法解决这个问题的任何帮助?代码停在这一行。我忘了提到我有一个主键,每次添加新记录时它都会增加一个。在数据库中它也是一个整数。我没有将它添加到此代码中,因为我认为当添加所有这些记录时它会自行添加。如果这是有道理的。
recordsAffected = cmd.ExecuteNonQuery,
我不确定这是什么问题。
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim recordsAffected As String
Dim cmdstring As String = "INSERT House (TypeofHouse, NumberofRooms, Location, Cost, Information, Picture) Values(@TYPEOFHOUSE, @NUMBEROFROOMS, @LOCATION, @COST, @INFORMATION, @PICTURE)"
conn = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\House.mdf;Integrated Security=True;User Instance=True")
cmd = New SqlCommand(cmdstring, conn)
cmd.Parameters.Add("@TYPEOFHOUSE", SqlDbType.NVarChar).Value = txtType.Text
cmd.Parameters.Add("@NUMBEROFROOMS", SqlDbType.Int).Value = txtNumOfRooms.Text
cmd.Parameters.Add("@LOCATION", SqlDbType.NVarChar).Value = txtLocation.Text
cmd.Parameters.Add("@COST", SqlDbType.Int).Value = txtCost.Text
cmd.Parameters.Add("@INFORMATION", SqlDbType.NVarChar).Value = txtInfo.Text
cmd.Parameters.Add("@PICTURE", SqlDbType.NVarChar).Value = txtLocation.Text
conn.Open()
recordsAffected = cmd.ExecuteNonQuery
conn.Close()