<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'need help!!' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'need help!!' posted on the 'VB.NET' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Wed, 23 May 2012 06:43:37 -0700</pubDate>
    <lastBuildDate>Wed, 23 May 2012 06:43:37 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>need help!!</title>
      <link>http://www.programmersheaven.com/mb/VBNET/409458/409458/need-help/</link>
      <description>On my form load event, i populate three comboboxes by code.... in the button click event i try to insert into the database and i use combobox.selecteditem and it generates an insert error.&lt;br /&gt;
but when i use combobox.selectedindex, it runs.&lt;br /&gt;
dont know wat to do.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/409458/409458/need-help/</guid>
      <pubDate>Tue, 17 Nov 2009 09:06:19 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: need help!!</title>
      <link>http://www.programmersheaven.com/mb/VBNET/409458/409462/re-need-help/#409462</link>
      <description>Have you looked at the contents of the Insert Statement to see why it is giving you an insert error? It'd be very helpful, for me to give you a good answer, if you provided the exact error messages and some sample code...&lt;br /&gt;
&lt;br /&gt;
Here is a suggestion on something to try so you can understand why your statement is crashing:&lt;br /&gt;
&lt;br /&gt;
MsgBox(ComboBox1.SelectedItem.GetType.ToString, vbOkOnly, "Test")&lt;br /&gt;
&lt;br /&gt;
You'll see that you get a type like "ListItem" or something from ComboBox1.SelectedItem. That is because ComboBox1.SelectedItem returns an OBJECT, not a VALUE, and that OBJECT is determined by the Datasource of the ComboBox (in this case you have added an item manually with ComboBox.Items.Add, so it uses a default data type and adds it to the datasource).....&lt;br /&gt;
&lt;br /&gt;
So here is some things you can use:&lt;br /&gt;
&lt;br /&gt;
ComboBox1.SelectedText 'this should work&lt;br /&gt;
ComboBox1.SelectedValue 'this works when you have a datasource and a valuemember set&lt;br /&gt;
ComboBox1.Items(ComboBox1.SelectedItem).Text&lt;br /&gt;
&lt;br /&gt;
Here is an example of how to check if something is selected, and get the value:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
'Assume ComboBox1 is the name of your combobox control
Dim ComboVal as STring = ""
If ComboBox1.SelectedValue &amp;gt; -1 Then 'Something is selected
  ComboVal = ComboBox1.SelectedText
Else
  'By Default you can type text into a ComboBox, if there is
  'text in the combo, and you haven't selected any, you can do
  'something here
End If
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/409458/409462/re-need-help/#409462</guid>
      <pubDate>Tue, 17 Nov 2009 10:31:52 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: need help!!</title>
      <link>http://www.programmersheaven.com/mb/VBNET/409458/409502/re-need-help/#409502</link>
      <description>hey seancampbell this is my code...&lt;br /&gt;
ON form load event..&lt;br /&gt;
Dim conn As New MySqlConnection&lt;br /&gt;
        conn.ConnectionString = "server=localhost;" _&lt;br /&gt;
                               &amp;amp; "database=cargomanager;" _&lt;br /&gt;
                              &amp;amp; "userid=root;" _&lt;br /&gt;
                              &amp;amp; "password=admin;"&lt;br /&gt;
        Try&lt;br /&gt;
            conn.Open()&lt;br /&gt;
        Catch myerror As MySqlException&lt;br /&gt;
            MsgBox("failed to connect to database")&lt;br /&gt;
        End Try&lt;br /&gt;
        sql0 = "select name as cname from agent"&lt;br /&gt;
        sql1 = "select name as dname from airline"&lt;br /&gt;
        sql2 = "select abbreviation as ename from destination"&lt;br /&gt;
        command.Connection = conn&lt;br /&gt;
        command.CommandText = sql0&lt;br /&gt;
        command1.Connection = conn&lt;br /&gt;
        command1.CommandText = sql1&lt;br /&gt;
        command2.Connection = conn&lt;br /&gt;
        command2.CommandText = sql2&lt;br /&gt;
        adapter.SelectCommand = command&lt;br /&gt;
        myadapter.SelectCommand = command1&lt;br /&gt;
        myadapter2.SelectCommand = command2&lt;br /&gt;
        adapter.Fill(dt)&lt;br /&gt;
        myadapter.Fill(dt1)&lt;br /&gt;
        myadapter2.Fill(dt2)&lt;br /&gt;
        ComboBox1.DataSource = dt&lt;br /&gt;
        ComboBox1.DisplayMember = "cname"&lt;br /&gt;
        ComboBox2.DataSource = dt1&lt;br /&gt;
        ComboBox2.DisplayMember = "dname"&lt;br /&gt;
        ComboBox3.DataSource = dt2&lt;br /&gt;
        ComboBox3.DisplayMember = "ename"&lt;br /&gt;
        conn.Close()&lt;br /&gt;
        conn.Dispose()&lt;br /&gt;
This is the insert statement on button click event..&lt;br /&gt;
Try&lt;br /&gt;
            sql = "insert into invoice(transactionid, description, quantity, weight, agent, airline, destination, price,time) values('" &amp;amp; TextBox1.Text &amp;amp; "', '" &amp;amp; TextBox2.Text &amp;amp; "', '" &amp;amp; TextBox3.Text &amp;amp; "', '" &amp;amp; TextBox4.Text &amp;amp; "', '" &amp;amp; ComboBox1.SelectedItem &amp;amp; "', '" &amp;amp; ComboBox2.Selecteditem &amp;amp; "', '" &amp;amp; ComboBox3.Selecteditem &amp;amp; "', '" &amp;amp; TextBox5.Text &amp;amp; "', NOW());"&lt;br /&gt;
            command.Connection = conn&lt;br /&gt;
            command.CommandText = sql&lt;br /&gt;
            command.ExecuteNonQuery()&lt;br /&gt;
            MsgBox("operation successfull")&lt;br /&gt;
        Catch myerror As MySqlException&lt;br /&gt;
            MsgBox("operation failed")&lt;br /&gt;
        End Try&lt;br /&gt;
this is the error msg&lt;br /&gt;
Operator '&amp;amp;' is not defined for string "insert into invoice(transactioni" and type 'DataRowView'.&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/409458/409502/re-need-help/#409502</guid>
      <pubDate>Wed, 18 Nov 2009 01:14:44 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: need help!!</title>
      <link>http://www.programmersheaven.com/mb/VBNET/409458/409607/re-need-help/#409607</link>
      <description>Sorry for my delay in responding...&lt;br /&gt;
&lt;br /&gt;
It seems to me that your problem isn't a SQL error, but instead a syntax error.&lt;br /&gt;
&lt;br /&gt;
.SelectedItem is an Object (in this case, a DataViewRow, because it is bound from a datatable). You cannot convert a DataViewRow into a string value... What you need to use is .SelectedValue or .SelectedItem.Value&lt;br /&gt;
&lt;br /&gt;
So change the sql= line to this:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
sql = "insert into invoice(transactionid, description, quantity, weight, agent, airline, destination, price,time) values('" &amp;amp; TextBox1.Text &amp;amp; "', '" &amp;amp; TextBox2.Text &amp;amp; "', '" &amp;amp; TextBox3.Text &amp;amp; "', '" &amp;amp; TextBox4.Text &amp;amp; "', '" &amp;amp; ComboBox1.SelectedItem.Value &amp;amp; "', '" &amp;amp; ComboBox2.SelectedItem.Value &amp;amp; "', '" &amp;amp; ComboBox3.SelectedItem.Value &amp;amp; "', '" &amp;amp; TextBox5.Text &amp;amp; "', NOW());"
&lt;/pre&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/409458/409607/re-need-help/#409607</guid>
      <pubDate>Thu, 19 Nov 2009 12:00:36 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: need help!!</title>
      <link>http://www.programmersheaven.com/mb/VBNET/409458/409641/re-need-help/#409641</link>
      <description>Thanks Sean for all your help.. I have tried the suggestion you gave me but they don't seem to work. I'm using vb.net express 2008 and mysql server 5.1. However when i use .selectedIndex or .SelectedText, the app doesnt crash...but fails to insert.&lt;br /&gt;
Besides intellisense does not give me the .SelectedItem.value option.&lt;br /&gt;
&lt;br /&gt;
By the way have you ever worked with winwedge???&lt;br /&gt;
Thanks for all your time.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/409458/409641/re-need-help/#409641</guid>
      <pubDate>Fri, 20 Nov 2009 08:03:30 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: need help!!</title>
      <link>http://www.programmersheaven.com/mb/VBNET/409458/409728/re-need-help/#409728</link>
      <description>try SelectedItem.Text&lt;br /&gt;
or&lt;br /&gt;
SelectedText&lt;br /&gt;
possibly&lt;br /&gt;
SelectedValue?&lt;br /&gt;
&lt;br /&gt;
Is this a Blue Squiggly Underline error (syntax error that wont let you compile) or is this a Run-Time error (the program runs, but crashes when it hits that line of code)?</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/409458/409728/re-need-help/#409728</guid>
      <pubDate>Sun, 22 Nov 2009 09:26:52 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: need help!!</title>
      <link>http://www.programmersheaven.com/mb/VBNET/409458/409753/re-need-help/#409753</link>
      <description>When i use selectedText, the program runs but fails to insert the values into the database.&lt;br /&gt;
selectedvalue and selecteditem crashes the program because they are objects and cant be converted to string.&lt;br /&gt;
selectedindex works but it inserts the index of the value and not the value itself. &lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/409458/409753/re-need-help/#409753</guid>
      <pubDate>Mon, 23 Nov 2009 00:15:35 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: need help!!</title>
      <link>http://www.programmersheaven.com/mb/VBNET/409458/409754/re-need-help/#409754</link>
      <description>When i use selectedText, the program runs but fails to insert the values into the database.&lt;br /&gt;
selectedvalue and selecteditem crashes the program because they are objects and cant be converted to string.&lt;br /&gt;
selectedindex works but it inserts the index of the value and not the value itself. &lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/409458/409754/re-need-help/#409754</guid>
      <pubDate>Mon, 23 Nov 2009 00:15:37 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: need help!!</title>
      <link>http://www.programmersheaven.com/mb/VBNET/409458/410127/re-need-help/#410127</link>
      <description>I am sorry I didn't catch this sooner... Firstly, I was just on a 2 week vacation, but more importantly, because I wasn't paying enough attention, for that I appologize...&lt;br /&gt;
&lt;br /&gt;
In your second reply, you pasted code... In this part of your code:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "cname"
ComboBox2.DataSource = dt1
ComboBox2.DisplayMember = "dname"
ComboBox3.DataSource = dt2
ComboBox3.DisplayMember = "ename"
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Do this:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "cname"
ComboBox1.ValueMember = "cname"
ComboBox2.DataSource = dt1
ComboBox2.DisplayMember = "dname"
ComboBox2.ValueMember = "dname"
ComboBox3.DataSource = dt2
ComboBox3.DisplayMember = "ename"
ComboBox3.ValueMember = "ename"
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
And use SelectedValue</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/409458/410127/re-need-help/#410127</guid>
      <pubDate>Tue, 01 Dec 2009 08:13:18 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: need help!!</title>
      <link>http://www.programmersheaven.com/mb/VBNET/409458/410162/re-need-help/#410162</link>
      <description>Big thanks to you Sean. I'm really grateful. Thanks so much.&lt;br /&gt;
Really looking forward to learning from you.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/409458/410162/re-need-help/#410162</guid>
      <pubDate>Wed, 02 Dec 2009 01:37:04 -0700</pubDate>
      <category>VB.NET</category>
    </item>
  </channel>
</rss>
