i want to put the values from three text boxes into one cell of my datagridview..

Dim myString as string = TextBox1.Text + " " + TextBox2.Text + " " + TextBox3.Text
YourDataGridView.Rows.Add(myString)

Thanks ,and i want to put some data from comboboxes into my datagridview but it is giving me Exception about Conversion my code is below:

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=grade;Integrated Security=True;Pooling=False")
        Dim cmd As SqlCommand

        If ComboClass.SelectedItem <> "" Or ComboDiv.SelectedItem <> "" Or ComboSubject.SelectedItem <> "" Or ComboTeacher.SelectedItem = "" Or ComboYrstart.SelectedItem <> "" Or ComboYrEnd.SelectedItem <> "" Then


            Try
                conn.Open()
                Dim query As String = "insert into TeacherSubject(Teacher,Class,Div,Subject,YearStart,YearEnd)values(@Teacher,@Class,@Div,@Subject,@YearStart,@YearEnd)"
                cmd = New SqlCommand(query, conn)
                cmd.Parameters.AddWithValue("@Teacher", (ComboTeacher.SelectedItem()))
                cmd.Parameters.AddWithValue("@Class", (ComboClass.SelectedItem()))
                cmd.Parameters.AddWithValue("@Div", (ComboDiv.SelectedItem()))
                cmd.Parameters.AddWithValue("@Subject", (ComboSubject.SelectedItem()))
                cmd.Parameters.AddWithValue("@YearStart", (ComboYrstart.SelectedItem()))
                cmd.Parameters.AddWithValue("@YearEnd", (ComboYrEnd.SelectedItem()))

                Dim NoOfRowsAffected As Integer = cmd.ExecuteNonQuery()//Exception
                MessageBox.Show("Teacher-Subject Details Inserted")
                LoadDataInDataGrid()
                ComboTeacher.SelectedItem = ""
                ComboClass.SelectedItem = ""
                ComboDiv.SelectedItem = ""
                ComboSubject.SelectedItem = ""
                ComboYrstart.SelectedItem = ""
                ComboYrEnd.SelectedItem = ""


            Catch ex As Exception
                MessageBox.Show(ex.ToString())

            Finally
                If conn.State = ConnectionState.Open Then
                    conn.Close()

                End If
            End Try
        Else
            MessageBox.Show("Please fill proper details")

        End If
    End Sub

try to change this :

cmd.Parameters.AddWithValue("@Teacher", (ComboTeacher.SelectedItem()))
cmd.Parameters.AddWithValue("@Class", (ComboClass.SelectedItem()))
cmd.Parameters.AddWithValue("@Div", (ComboDiv.SelectedItem()))
cmd.Parameters.AddWithValue("@Subject", (ComboSubject.SelectedItem()))
cmd.Parameters.AddWithValue("@YearStart", (ComboYrstart.SelectedItem()))
cmd.Parameters.AddWithValue("@YearEnd", (ComboYrEnd.SelectedItem()))

to this :

cmd.Parameters.AddWithValue("@Teacher", ComboTeacher.SelectedItem.ToString)
cmd.Parameters.AddWithValue("@Class", ComboClass.SelectedItem.ToString)
cmd.Parameters.AddWithValue("@Div", ComboDiv.SelectedItem.ToString)
cmd.Parameters.AddWithValue("@Subject", ComboSubject.SelectedItem.ToString)
cmd.Parameters.AddWithValue("@YearStart", ComboYrstart.SelectedItem.ToString)
cmd.Parameters.AddWithValue("@YearEnd", ComboYrEnd.SelectedItem.ToString)

and this :

Dim NoOfRowsAffected As Integer = cmd.ExecuteNonQuery()//Exception

to this :

cmd.ExecuteNonQuery()

it is still S

it is still showing me the Exception i have given below the message it is showing me please give me a solution to this soon.

System.Data.SqlClient.SqlException was caught
  Class=16
  ErrorCode=-2146232060
  LineNumber=1
  **Message=Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query.**
  Number=257
  Procedure=""
  Server=.\SQLEXPRESS
  Source=.Net SqlClient Data Provider
  State=3
  StackTrace:
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
       at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
       at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
       at grading_system.frmTeaches.Button1_Click(Object sender, EventArgs e) in C:\Users\Pratik\Desktop\project\form-2\grading system\grading system\frmTeaches.vb:line 196
  InnerException: 

i got it i made a mistake in defining data type to subject attribute i used varbinary intead of varchar and i have corrected it and now its working fine..thanks Dude

i want to delete the data from datagridview but not from the database but im not getting the logic for it cn u suggests me i wnt it to change the status in the database...

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.