Click here to Skip to main content
15,909,242 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 tables one data,sort finalsort.

the columns are lotno,name,type,size(nvarchar)-data, sort and finalsort.

but data is getting inserted in database but showing error as " input string is nt in the correcct format." at line me.finalsorttableadapter.insert/

sometimes error showing as string cannot be converted to double.

in size column i am entering it as 1.2x2.4 and its getting updated in database but showing error in next me.finalsortadapter.insert

actually in 1st form, i am inserting data in database.

in 2nd form, i am retriving data from database through combobox selection.

in 3rd form, again i am retreiving data from form2 and dispalying it in 3rd form.

and the error is showing in 3rd form.

so my values are traversing from table data to sort to finalsort.

can anyone tell me how to convert string to double?

i wrote convert.todouble(textbox4.text) but its not working.
Posted
Comments
sudeshna from bangkok 10-Jul-13 0:17am    
Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=record;user=sa;password=gariahat")
Dim da As New SqlDataAdapter
Dim cmd As New SqlCommand
Dim ds As New DataSet
'Dim dr As SqlDataReader
cmd.Connection = cn
cn.Open()
'cmd.CommandText = "insert into sort(lot_no,name,type,shape,size,place,weight,issue_dt) values (' " & ComboBox1.Text & " ',' " & TextBox2.Text & " ',' " & TextBox3.Text & " ',' " & TextBox4.Text & " ',' " & TextBox5.Text & " ',' " & TextBox6.Text & " ',' " & TextBox7.Text & " ','" & DateTimePicker1.Value & " ');insert into finalsort(lot_no,name,type,shape,size,place,weight,issue_dt,return_dt) values (' " & ComboBox1.Text & " ',' " & TextBox2.Text & " ',' " & TextBox3.Text & " ',' " & TextBox4.Text & " ',' " & TextBox5.Text & " ',' " & TextBox6.Text & " ',' " & TextBox7.Text & " ',' " & TextBox8.Text & " ',' " & DateTimePicker1.Value & " ')"
cmd.CommandText = "insert into finalsort(lot_no,name,type,shape,size,place,weight,issue_dt,return_dt) values (' " & ComboBox1.Text & " ',' " & TextBox2.Text & " ',' " & TextBox3.Text & " ',' " & TextBox4.Text & " ',' " & TextBox5.Text & " ',' " & TextBox6.Text & " ',' " & TextBox7.Text & " ',' " & Format(CDate(TextBox8.Text), "MM/dd/yyyy") & " ',' " & Format(CDate(DateTimePicker1.Value), "MM/dd/yyyy") & " ')"
cmd.ExecuteNonQuery()
MsgBox("Data successfully added", MsgBoxStyle.Information)

Me.FinalsortTableAdapter.Insert(ComboBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox7.Text, Convert.ToDateTime(TextBox8.Text), Format(CDate(DateTimePicker1.Value), "dd/MM/yyyy"))
Me.FinalsortTableAdapter.Fill(Me.RecordDataSet.finalsort)
Me.ComboBox1.Text = ""
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
Me.TextBox5.Text = ""
Me.TextBox6.Text = ""
Me.TextBox7.Text = ""
Me.TextBox8.Text = ""
Me.DateTimePicker1.Text = ""


this is the code and getting error just after msgbox
ArunRajendra 10-Jul-13 0:22am    
I am not sure about your question I am guessing that you are trying to save 1.2x2.4 into the database whose column is double. If its so then its not possible. You need to change the datatype of the field to string.
sudeshna from bangkok 10-Jul-13 0:41am    
please can anyone help me.

i will be obliged.
thanks
sudeshna from bangkok 10-Jul-13 0:42am    
no, i am column is varchar
sudeshna from bangkok 10-Jul-13 0:43am    
and the error showing in table adapter line. my size value is getting inserted in database but showing error when its executing the next line aftr msgbox

1 solution

It is better practice to try to parse the string:

VB
Dim dbl As Double
If Double.TryParse(textbox4.Text, dbl) Then
  'use the variable dbl since it has converted
Else 
  'it has not - invalid string format for double
End If
 
Share this answer
 
Comments
sudeshna from bangkok 10-Jul-13 1:09am    
actualy nothing is getting inserted in my table adapter.insert. when i am executing from back binding data, no records are showing.
sudeshna from bangkok 10-Jul-13 1:21am    
in this line,how do i convert string to double?

Me.FinalsortTableAdapter.Insert(ComboBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox7.Text, Convert.ToDateTime(TextBox8.Text), Format(CDate(DateTimePicker1.Value), "dd/MM/yyyy"))
sudeshna from bangkok 10-Jul-13 1:39am    
Conversion from string " 2.5x1.2 " to type 'Double' is not valid.

i am getting this error in last form.

but previous form no problem i am facing.
Idle_Force 10-Jul-13 9:31am    
That is not a valid double value - cannot convert that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900