Inserting into a datagrid

Results 1 to 2 of 2

Thread: Inserting into a datagrid

  1. #1
    Join Date
    Dec 1969

    Default Inserting into a datagrid

    Hi there i am currently trying to insert into a datagrid but i always get either of the two following errors- ORA-00936: missing expression or Iconversion error. I am not sure on a couple of things so i have included my insert function adn my bind data function although i am not sure how this is supposed to work and the type of code i should include in it. I can get to where i need to insert the new records but when i hit the insert button i get those errors. I would also like to know how i can fill the datagrid with this new information. the database itself is oracle and the fields (6 of them are all varchar2). I would appreciate if someone could have a look at this and help me out. thanks<BR><BR>ublic Sub doInsert(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)<BR> If e.CommandName = "Insert" Then<BR> Dim storID As String<BR> Dim txtStorID As TextBox<BR> txtStorID = e.Item.FindControl("add_storID")<BR> storID = txtStorID.Text<BR><BR> Dim storName As String<BR> Dim txtStorName As TextBox<BR> txtStorName = e.Item.FindControl("add_storName")<BR> storName = txtStorName.Text<BR><BR> Dim storAddress As String<BR> Dim txtStorAddress As TextBox<BR> txtStorAddress = e.Item.FindControl("add_storAddress")<BR> storAddress = txtStorAddress.Text<BR><BR> Dim storCity As String<BR> Dim txtStorCity As TextBox<BR> txtStorCity = e.Item.FindControl("add_city")<BR> storCity = txtStorCity.Text<BR><BR> Dim storState As String<BR> Dim txtStorState As TextBox<BR> txtStorState = e.Item.FindControl("add_state")<BR> storState = txtStorState.Text<BR><BR> Dim storZip As String<BR> Dim txtStorZip As TextBox<BR> txtStorZip = e.Item.FindControl("add_zip")<BR> storZip = txtStorZip.Text<BR><BR> Dim strSQL As String<BR> strSQL = "INSERT INTO STORES (id, stor_name, stor_address, city, state, zip) " & _<BR> "VALUES (@storID, @storName, @storAddress,@storCity,@storState,@storZip)"<BR><B R> Const strConnStr As String = "Provider=MSDAORA.1;user id=;data source=;password="<BR> Dim con As New OleDb.OleDbConnection(strConnStr)<BR> con.Open()<BR> Dim cmdExp As New OleDb.OleDbCommand(strSQL, con)<BR> Dim storIDParam As New OleDb.OleDbParameter("@storID", OleDb.OleDbType.VarChar, 50)<BR> storIDParam.Value = txtStorID.Text<BR> cmdExp.Parameters.Add(storIDParam)<BR> Dim storNameParam As New OleDb.OleDbParameter("@storName", OleDb.OleDbType.VarChar, 50)<BR> storNameParam.Value = txtStorName.Text<BR> cmdExp.Parameters.Add(storNameParam)<BR> Dim storAddParam As New OleDb.OleDbParameter("@storAddress", OleDb.OleDbType.VarChar, 50)<BR> storAddParam.Value = txtStorAddress.Text<BR> cmdExp.Parameters.Add(storAddParam)<BR> Dim storCityParam As New OleDb.OleDbParameter("@storCity", OleDb.OleDbType.VarChar, 50)<BR> storCityParam.Value = txtStorCity.Text<BR> cmdExp.Parameters.Add(storCityParam)<BR> Dim storStateParam As New OleDb.OleDbParameter("@storState", OleDb.OleDbType.VarChar, 50)<BR> storStateParam.Value = txtStorState.Text<BR> cmdExp.Parameters.Add(storStateParam)<BR> Dim storZipParam As New OleDb.OleDbParameter("@storZip", OleDb.OleDbType.VarChar, 50)<BR> storZipParam.Value = txtStorZip.Text<BR> cmdExp.Parameters.Add(storZipParam)<BR><BR> cmdExp.ExecuteNonQuery()<BR> con.Close()<BR> dgStores.EditItemIndex = -1<BR> &#039;OracleDataAdapter1.Fill(DsStores1)<BR> &#039;dgStores.DataBind()<BR> &#039;DataBind()<BR> &#039; dgStores.DataBind()<BR> BindData()<BR> End If<BR><BR><BR><BR><BR><BR><BR><BR><BR> End Sub<BR> Public Sub BindData()<BR> Const strConnStr As String = "Provider=MSDAORA.1;user id=;data source=;password=" &#039;<BR> Dim objConn As New OleDb.OleDbConnection(strConnStr)<BR> objConn.Open()<BR><BR> &#039;2. Create a command object for the query<BR><BR><BR> Const strSQL As String = "SELECT * FROM STORES"<BR> &#039;Dim resultsDataSet As New DataSet<BR> &#039; Dim myDataAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(strSQL, objConn)<BR> &#039; myDataAdapter.Fill(resultsDataSet)<BR><BR> Dim objCmd As New OleDb.OleDbCommand(strSQL, objConn)<BR><BR> &#039;3. Create/Populate the DataReader<BR> Dim objDR As OleDb.OleDbDataReader<BR> objDR = objCmd.ExecuteReader()<BR><BR> dgStores.DataSource = objDR<BR> dgStores.DataBind()<BR> objDR.Close()<BR> objConn.Close()<BR><BR> End Sub<BR><BR>End Class<BR><BR>PS my data connections appear to be working fine!!!

  2. #2
    Join Date
    Dec 1969

    Default RE: Inserting into a datagrid

    You can&#039;t take out the .Text part, because txtStorZip is a TextBox control. You want the Text entered by the user, so you need to use .Text<BR><BR>Now, when inserting a new record, is there a value entered into the ZipCode textbox? Perhaps it is empty, but the database requires a value? Just a shot in the dark. The error message - "missing expression" - leads me to think that the problem is with the SQL statement being sent to the database. Like you are perhaps missing a required field, or are passing in an invalid value.<BR><BR>What happens if you try to run the query directly against the database (i.e., not through a Web page here, but through Oracle&#039;s Query Analyzer-like tool)? Does it work, or do you get an error?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts