I am working on a system right now in which When I put some value in my first text box (For eg. A primary key), I want the other textboxes to fetch the related data from my database and automatically get filled with it. I'm working on visual basic. I am new to this. For some Reason, it keeps on telling me that datarowcollection cannot be converted to string. Please help me get his working.Here is the code:-

Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.ClickDim Cn As New SqlClient.SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\admin\Documents\Asset_Manager.mdf';Integrated Security=True;Connect Timeout=30")Dim StrCmd As String="Select * from Asset_Master where Asset_Id='" & txt_allocate_asset_id.Text & "' "Dim Command As SqlCommandDim da As SqlDataAdapterDim dt As New DataTableTryCn.Open()Command=New SqlCommand(StrCmd, Cn)da=New SqlDataAdapter(Command)Command.ExecuteNonQuery()da.Fill(dt)txt_demo_model_no.Text=dt.Rows[0][model_no].ToString()//The error lineCatch ex As ExceptionThrow exEnd TryEnd Sub
share|improve this question
  • Actual code samples would help with troubleshooting this.– AfroThundrFeb 12 at 20:21
  • I am trying to upload a pic but was unable to for some reason. I'll try again– Dwij ShastriFeb 13 at 16:39
  • How does this website work? I'm using it for the first time. I am not able to post a pic nor am I able to put in the code, please help– Dwij ShastriFeb 13 at 16:59
  • Code formatting is accomplished by indenting the entire block by 4 spaces. See the help for more examples.– AfroThundrFeb 13 at 17:04
  • Thanks for the suggest. So there you go i hope you got the code properly.– Dwij ShastriFeb 13 at 17:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.