I am helping a friend with a project in Visual Basic, it is a program that uses a SQL database. There are some rows in the database, we can review them just fine. So the SELECT quesries are fine, it is the INSERT queries that we are having problems with.

We keep getting an exception when we try to insert data into the database when the "Finish" button is clicked. And if you press the continue button on the exception dialog, and then you press finish again, you get a different exception.

Exception from the first attempt

System.ArgumentException: No mapping exists from DbType Object to a known SqlDbType.
at System.Data.SqlServerCe.SqlCeType.FromDbType(DbType type)
at System.Data.SqlServerCe.SqlCeParameter.set_DbType(DbType value)
at WindowsApplication1.usersDataSetTableAdapters.UsersTableAdapter.InitCommandCollection()
at WindowsApplication1.usersDataSetTableAdapters.UsersTableAdapter.get_CommandCollection()
at WindowsApplication1.usersDataSetTableAdapters.UsersTableAdapter.Name(String name1)

Pressed "Continue"

Exception from the second attempt
System.NullReferenceException: Object reference not set to an instance of an object.
at WindowsApplication1.usersDataSetTableAdapters.UsersTableAdapter.Name(String name1)


Here is the code around the area that throws the exception:

Function GetUserName() As String
        If TypeOf My.User.CurrentPrincipal Is  _
        Security.Principal.WindowsPrincipal Then
            ' The application is using Windows authentication.
            ' The name format is DOMAIN\USERNAME.
            Dim parts() As String = Split(My.User.Name, "\")
            Dim username As String = parts(1)
            Return username
        Else
            ' The application is using custom authentication.
            Return My.User.Name
        End If
    End Function
    Public username As String = GetUserName()
    Dim usersTableAdapter As New usersDataSetTableAdapters.UsersTableAdapter()
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            name = (Form1.TextBox1.Text + " " + Form1.TextBox2.Text + " " + Form1.TextBox4.Text)
            usersTableAdapter.Name(name)
            usersTableAdapter.Attention(Form1.ComboBox1.Text, name)
            usersTableAdapter.At_Ease(Form1.ComboBox2.Text, name)
            usersTableAdapter.Hand_Salute(Form1.ComboBox3.Text, name)
            usersTableAdapter.Present_Arms(Form1.ComboBox4.Text, name)
            usersTableAdapter.Order_Arms(Form1.ComboBox5.Text, name)
            usersTableAdapter.Rest(Form1.ComboBox6.Text, name)
            usersTableAdapter.About_Face(Form1.ComboBox7.Text, name)
            usersTableAdapter.Right_Face(Form1.ComboBox8.Text, name)
            usersTableAdapter.Left_Face(Form1.ComboBox13.Text, name)
            usersTableAdapter.Eyes_Right(Form1.ComboBox14.Text, name)
            usersTableAdapter.Ready_Front(Form1.ComboBox15.Text, name)
            usersTableAdapter.Forward_March(Form3.ComboBox1.Text, name)
            usersTableAdapter.Quick_Time(Form3.ComboBox2.Text, name)
            usersTableAdapter.Double_Time(Form3.ComboBox3.Text, name)
            usersTableAdapter.Mark_Time(Form3.ComboBox4.Text, name)
            usersTableAdapter.Half_Step(Form3.ComboBox13.Text, name)
            usersTableAdapter.Halt(Form3.ComboBox5.Text, name)
            usersTableAdapter.Right_Step(Form3.ComboBox6.Text, name)
            usersTableAdapter.Left_Step(Form3.ComboBox7.Text, name)
            usersTableAdapter.Change_Step(Form3.ComboBox8.Text, name)
            usersTableAdapter.To_The_Rear(Form3.ComboBox14.Text, name)
            usersTableAdapter.Right_Flank(Form3.ComboBox9.Text, name)
            usersTableAdapter.Left_Flank(Form3.ComboBox10.Text, name)
            usersTableAdapter.Rout_Step(Form3.ComboBox11.Text, name)
            usersTableAdapter.Parade_Rest(Form3.ComboBox12.Text, name)

    End Sub

Does anyone know what could be causing this? Because I am completely clueless.

Wrong forum, you need the dot net forum...

I was looking for it, but I couldn't really find it. Sorry. I guess I could have tried harder to find it. But eh, close enough, right? Anyways, the problem has actually been solved, I just can't figure out how to delete the thread. Because marking it as solved would keep it here.

This forum doesn't have the same thread tool setup as other vBulletin forums.

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.