Miguel:
your connection.Open() should be in the try but that isn't your problem.
The id should be automatically generated. What isn't working? Are you
getting an error? is the row simply not getting added? Is this access?
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:...
> Hello,
>
> I need to create a new record in a database.
> The database has 3 fields: [id] (autonumber), [title] and [text] (strings)
>
> When I create the record how should I create the [id] value?
>
> Does the database insert it automatically?
>
> Do I need to create a random number?
> How can I do it to not repeat the id's already exist in the table?
>
> My code is not working but it seems fine to me:
>
> Dim connectionString As String =
> System.Configuration.ConfigurationSettings.AppSett ings("connectionString")
> Dim dbConnection As System.Data.IDbConnection = New
> System.Data.OleDb.OleDbConnection(connectionString )
>
> Dim queryString As String = "INSERT INTO [t_news] ([title], [text])
> VALUES (@title, @text)"
> Dim dbCommand As System.Data.IDbCommand = New
> System.Data.OleDb.OleDbCommand
> dbCommand.CommandText = queryString
> dbCommand.Connection = dbConnection
>
> Dim dbParam_title As System.Data.IDataParameter = New
> System.Data.OleDb.OleDbParameter
> dbParam_title.ParameterName = "@title"
> dbParam_title.Value = title
> dbParam_title.DbType = System.Data.DbType.String
> dbCommand.Parameters.Add(dbParam_title)
>
> Dim dbParam_text As System.Data.IDataParameter = New
> System.Data.OleDb.OleDbParameter
> dbParam_text.ParameterName = "@text"
> dbParam_text.Value = text
> dbParam_text.DbType = System.Data.DbType.String
> dbCommand.Parameters.Add(dbParam_text)
>
> Dim rowsAffected As Integer = 0
> dbConnection.Open
> Try
> rowsAffected = dbCommand.ExecuteNonQuery
> Finally
> dbConnection.Close
> End Try
>
> Thanks,
> Miguel
>