DataSource Controls :: Save Values In GridView With 2 Tables
May 29, 2010
I have a form with several DropDownlists and TextBoxes, Each dropdownlist depends on the selection of the previouse one.. and there is a submit button. Once the user clicks on it, information entered by the user is displayed in a GridView and saved as well in the database. The GridView holdes information from two tables I used joining) , but once I click on the Submit button I receive this error: Arithmetic overflow error converting varchar to data type numeric. The statement has been terminated. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Arithmetic overflow error converting varchar to data type numeric. The statement has been terminated. Source Error:
[Code]....
Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial
Class Members_MembersCalculator
Inherits System.Web.UI.Page
Protected Sub CalculateButton_Click(ByVal sender
As Object,
ByVal e As System.EventArgs)
Handles CalculateButton.Click
Dim objConnection As SqlConnection
Dim objDataCommand As SqlCommand
Dim c_manu, c_model, c_date
As String
Dim sSQL As
String
Dim ConnectionString As
String
Dim c_factor As
Double
Dim c_result
As Double
Dim c_milage As
Double
Dim c_id As
Integer
Dim c_year As
Integer
c_manu = ManDropDownList.Text
c_year = YearDropDownList.Text
c_model = ModelDropDownList.Text
c_milage = MilageTextBox.Text
c_factor = FactorDropDownList.Text
c_id = CarIDDropDownList.Text
c_date = CarDateTextBox.Text
c_result = c_factor * c_milage
ConnectionString = WebConfigurationManager.ConnectionStrings("Carbon_free_ConnectionString").ConnectionString
objConnection = New SqlConnection(ConnectionString)
objConnection.Open()
sSQL = "Insert into car (Manufacture, year, Model, car_factor)" & _
"values('" & c_manu &
" ', ' " & c_year & " ',' " & c_model &
" ', ' " & c_factor &
" ')"
objDataCommand = New SqlCommand(sSQL, objConnection)
objDataCommand.ExecuteNonQuery()
objConnection.Close()
objConnection = New SqlConnection(ConnectionString)
objConnection.Open()
sSQL = "Insert into car_Result (car_id, car_Result_Date, Car_result)" & _
"values('" & c_id &
" ', ' " & c_date & " ',' " & c_result &
" ')"
objDataCommand = New SqlCommand(sSQL, objConnection)
objDataCommand.ExecuteNonQuery()
objConnection.Close()
msgLabel.Text = "Your records have been calculated successfuly, Thank you."
'CarDateTextBox.Text = ""
'MilageTextBox.Text = ""
CarGridSqlDataSource.DataBind()
CarGridView.DataBind()
End Sub
End
Class
i have an insert statement, and what i would like to do iswhen the value of table1 is entered, that value enters into table 2, so for example, heres my insert statement
INSERT INTO Cards (Name, Desc, id) VALUES ( @Name, @Desc, @id) INSERT INTO CardTP (NameSet, Desc, id)
Now, what i would like to do is that, i will specify all those individual values myself, BUT, when it now comes to the "id" field, when an id is entered for the "Cards" table, the SAME id should also be entered in the id column of the "CardTP" table. how i could enter the value of one table, into another tables row (having the same value) as i want the Cards and CardsTP table to be related in the id fields.
I have an editable gridview with blank cells. User enters some numeric data in cells and also user can clicks a button to add new row to gridview. My problem is that, as soon as button click event is fired, the page refreshes & the gridview becomes empty. Can anybody tell me, how can I save values in gridview until the user saves all changes to the server in the end
I have a gridview inside which there are 4-5 checkboxes. In that gridview, I have 10 rows too. So, Now what i want is.
IF I check, 2 checkboxes and don't check remaining checkboxes. how to save the value of the checked checkboxes value as Y and unchecked checkboxes value as N into the database.
I have a gridview and users would select some records and would click on the submit button and i will be saving those records into database using a stored proc.... now .... just below the gridview and above the submit button there are few checkboxes by default they wud be checked. How would i save the selected values and the checked boxes in database i wrote the stored proc for the gridview but how would i save the checked checkboxes into the same table.
For i As Integer = 0 To gvSelectScreen.Rows.Count - 1 Dim chkTemp As CheckBox = TryCast(gvSelectScreen.Rows(i).FindControl("cbStatus"), CheckBox) If chkTemp.Checked Then ContractNumber = gvSelectScreen.Rows(i).Cells(0).Text ClientProgramNumber = gvSelectScreen.Rows(i).Cells(1).Text ClientProgramName = gvSelectScreen.Rows(i).Cells(2).Text StartDate = CType(gvSelectScreen.Rows(i).FindControl("txtStartDate"), TextBox).Text EndDate = gvSelectScreen.Rows(i).Cells(5).Text Dim connStr As String = ConfigurationManager.ConnectionStrings("MainConnectionString").ConnectionString Dim myCon As New SqlConnection(connStr) Dim cmd As New SqlCommand("usp_ParametersFromGrid") Dim dt As New DataTable cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add("@ContractNumber", SqlDbType.VarChar, 22).Value = ContractNumber.ToString() cmd.Parameters.Add("@ClientProgramNumber", SqlDbType.VarChar, 22).Value = ClientProgramNumber.ToString() cmd.Parameters.Add("@ClientProgramName", SqlDbType.VarChar, 100).Value = ClientProgramName.ToString() cmd.Parameters.Add("@StartDate", SqlDbType.VarChar, 20).Value = StartDate.ToString() cmd.Parameters.Add("@EndDate", SqlDbType.VarChar, 20).Value = EndDate.ToString() cmd.Parameters.Add("@RequestID", SqlDbType.VarChar, 50).Value = RequestID.ToString() cmd.Connection = myCon myCon.Open() cmd.ExecuteNonQuery() myCon.Close() End If
Now above the submit button as i said, there are few checkboxes and they are checked by default...how would i save the selected item (in the gridview and the checked checkbox values in the same row in the database(sql server)
I get this while trying to save an edit in a Gridview. I removed the @albumUID whivh it automaticlly gerneated when a new record is enteredinto the database. BanUID is the only other uniqueidentifier but in this table it is not set to auto generate,I get the same response if I make a Detialviews and unsert.Here's the code
<asp:SqlDataSource ID="SqlDSAddAlbum" runat="server" ConnectionString="<%$ ConnectionStrings:MyCDsConnectionStringHome %>" DeleteCommand="DELETE FROM [Album] WHERE [AlbumUID] = @AlbumUID"
i'm new to programming and i'm doing a project of ana e-store, i have a data gridview that brings data from a data base and it have to more templeate files one a textbox and the other one is a label. and i have a button outside the grivdview. what i need that when i press on this button it will take the values from the grid view and insert them into a new sql table.
[Code]....
and here is the VB code that i'm trying to use with no luck : [Code]....
I have a gridview showing values from two tables accommodation and pic (left join on accommodation). If there is no pic uploaded I want to display the row without the pic. So in the gridview I first check to see if the picid is null, if it is i don't render any 'a href' code , if it's isn't i do.
The problem that i'm having is that instead of the image showing up in the gridview itemtemplate i get ','_blank','toolbar=no,menubar=no'))" >
Here is my .aspx code
SelectCommand="SELECT pic.picid, aspnet_Users.Username, accommodation.location, accommodation.type,accommodation.description, convert(varchar,accommodation.createdate,101) as createdate
how to bind selected values from two tables to gridview data source, that two tables are from two databases. i created a view by using these two.But error is getting with this query,that is invalid object derivdtbl_1.Expr1. how to fix this?
SELECT dbo.Station_Channel.St_id, dbo.Station_Channel.lid, dbo.Station_Channel.Edit, dbo.Station_Channel.lChannelName, dbo.Station_Channel.lShort, dbo.Station_Channel.lPosition, dbo.Station_Channel.lTransformData, dbo.Station_Channel.lUnits, dbo.Station_Channel.lDecimalPts, dbo.Station_Channel.parameter, dbo.Station_Channel.function_value, derivdtbl_1.Expr1 FROM dbo.Station_Channel CROSS JOIN (SELECT MAX(Fecha) AS Expr1 FROM MeteoStation.dbo.Datos) AS derivdtbl_1 WHERE (dbo.Station_Channel.Edit = 1)
I had just started with Visual Studio 2008 + VB.net. I've now designed my tables, and basic gridview functions properly.Now I'm faced with the problem of having to calculate a value based on 2 - 3 columns/data in the gridview, display the result in an existing column in the same gridview, and saving the calculated value in the datasource.I had initially created the "Total" column as a textbox displaying a manually calculated amount that is saved in the datasource. Now, I want to change the field to auto-calculate based on 2 other columns.
string studentno = "select regno from stu_ref where batch='" + dropbatch.SelectedItem.ToString() + "'"; SqlDataAdapter dastudent = new SqlDataAdapter(studentno, cn1); DataSet dsstudent = new DataSet();[code]....
form the above coding i will get all values form the table stu_ref of regno of student now i need to get the first and the last regno from the table
i have a problem in joining two tables the reason ismy first table persdata is having common field as pno (a single row in a particular person) and the second tables is also having pno(having muti entry for a person as this table is of qualification and a person may have more than 3 qualifications and their grading)sample persdata(table)pno name coy appt sample qual(table)pno qual grading recommendationi tried my best to do it and not able to proceedi want the output in a single row as in persdata to a gridview with all the qual combined in one coloumn and all the recommendations combined in one coloumn for a person.
I have a code here,where it will store temporary data in a gridview from textbox where when the data is stored temporarily in gridview. Alternately,it will be linked to search the word in google. Now i want to save the values in the gridview to database. I m new to asp.net,seeking ideas from all. Here is my .aspx code:
I have a gridview that I'm trying to update the Date something is corrected in the database. When I am putting a new value in, it is updating, but it isn't updating the new value, just the old one that is already there. I cannot figure out why this is happening.
I have a checkbox column in a Gridview that I would like to use to insert the value of one cell in the row into an access database. There will be a maximun of five cells allowed to be selected so there can be one value written to one field in the database up to the maximum of the five fields. The access database has five columns: Selection1 ,Selection2, Selection3 ,Selection4 and Selection5
When the checkbox is checked, the value of one cell (PliD) should be written to each field in the database. Ie: checkbox in row 1 should write PliD value to Selection1, checkbox in row 2 should write PliD value to Selection2, checkbox in row 3 should write PliD value to Selection3 and on depending on which checkbox has been checked. I am not sure how to get the value of the checkbox and write it into the corresponding fields in the database.
So far i've populated my grid view with my roomID. however using data reader I don't seem to be able to get more than one column to auto generate even though i'm now looking for three values : SELECT tt_roomEquip.roomID, tt_room.roomCapacity, tt_equip.equipTitle is my select bit of the sql, though it's only putting roomID into my grid view.
I have a little problem concerning the saving in two associated tables !
explanation :
i am using sql server 2008 and MVC 1.0
for the saving and edition i used the standard methode, wich is (using control and repository classes, and then "the add view" fonctionality).
in my case , i have a table A associated with another table B, this means that in the A i have other columns belonging to the table B, but when using the Add view, it doesn't add the ather column of the table B, even if in the sql server, in the design of the table i find these columns!
the code for grabbing data is:
[Code]....
and for the view here is the code generated:
[Code]....
the aim here is that i want to add for exampl an other property: [Code]....