Imports System.Data.OleDb

Public Class Form3

    Dim cmd As New OleDbCommand
    Dim rdr As OleDbDataReader
    Dim strmsg As String
    Dim db As New mydb1
    Dim da As New OleDbDataAdapter
    Dim dset As New DataSet

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        db.dbconnection()

        strmsg = "select Class from Week"

        cmd = db.dbcommand(strmsg)


        rdr = cmd.ExecuteReader
        'While rdr.Read
        'ComClass1.Items.Add(rdr.Item("class"))

        'End While
        rdr.Close()
    EndSub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles  ComboBox1.SelectedIndexChanged
        cmd.CommandText = "select * from Week where Nme = '"& ComboBox1.Text.ToString &"' "
        rdr = cmd.ExecuteReader
        rdr.Read()
        txtClass.Text = rdr.Item("Class")

        rdr.Close()
    EndSub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        cmd = db.dbcommand("insert into Week(Nme,Score,Class) values(Default,'"& Val(txtScore.Text) &"',Default ) where Nme = '"& ComboBox1.Text.ToString &"'")
        cmd.ExecuteNonQuery()
        Me.Hide()
        'cmd.Dispose()

    EndSub
EndClass

following are the screenshots of error and my table

Dani AI

Generated

Quick diagnosis: the SQL in your save handler is invalid. An INSERT statement does not accept a WHERE clause — that pattern is used for UPDATE. If the intent is to change the Score for an existing row use UPDATE; if you want to add a new row use INSERT without WHERE. Also avoid building SQL by concatenating user text (SQL injection and type errors); use parameterized commands and let the provider handle data types.

Example (update an existing row — OleDb uses positional parameters):

Dim selectedName As String = ComboBox1.Text
Dim scoreValue As Integer = Integer.Parse(txtScore.Text)

Using conn As New OleDbConnection(connectionString)
    conn.Open()
    Using cmd As New OleDbCommand("UPDATE Week SET Score = ? WHERE Nme = ?", conn)
        cmd.Parameters.AddWithValue("?", scoreValue)
        cmd.Parameters.AddWithValue("?", selectedName)
        cmd.ExecuteNonQuery()
    End Using
End Using

Example (insert a new row):

Using cmd As New OleDbCommand("INSERT INTO Week (Nme, Score, Class) VALUES (?, ?, ?)", conn)
    cmd.Parameters.AddWithValue("?", selectedName)
    cmd.Parameters.AddWithValue("?", scoreValue)
    cmd.Parameters.AddWithValue("?", classValue) 'omit if Class has a DB default
    cmd.ExecuteNonQuery()
End Using

Practical tips and cautions:

  • OleDb treats ? parameters positionally — add parameters in the same order as the placeholders.
  • Prefer typed parameters (Add with OleDbType) over AddWithValue when exact types matter.
  • If a column name might be a SQL/DB reserved word (e.g., Class), bracket it: [Class].
  • Use Using blocks to ensure disposal, and wrap DB calls in Try/Catch to log full exception text.
  • Verify your mydb1 wrapper actually returns an open OleDbConnection or a command with a valid Connection — this is often the hidden cause, as suggested.

Recommended Answers

All 6 Replies

You have a few problems to clear up before we can answer your question.

  1. You need to use the Code tool to insert code or you lose all formatting (I fixed it up for you this time)
  2. You did not attach any screenshots
  3. Your question is confusing

Please provide more detail.

By the way, you don't need to use ToString on something that is already a string. Just use

ComboBox1.Text

how i attach the screen shots

In the editor's toolbar, click "Files". You should get some "Choose" buttons. If you select a file, it will be automatically uploaded and attached.

i try to attach my screenshots,but i cant,please help with this

here i am attaching the screen shots,please have a look on this

If you are not going to provide full information then you are not going to get help. For example, what is

 Dim db As New mydb1

I presume mydb1 is a user written class but there is no way of knowing what this is because you haven't provided the code. We don't know what your database looks like or even what type of database it is because, again, you seem more interested in playing twenty questions than in getting an answer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.