Showing posts with label save. Show all posts
Showing posts with label save. Show all posts

Thursday, March 29, 2012

DATATYPE PROBLEM(cross)

I have a column in my table BizdekiFiyat . The datatype = float length =8
(to save money values).. It is impossible to change these attributes for
some reasons.
It has records like This
BizdekiFiyat
110
24
29.5
31.35
I use Vb.Net . I use ExecuteReader To select values from my db..
After first attemp
Dim BizdekiFiyat As Integer OR Dim BizdekiFiyat As Decimal
IT returns
110
24
295
3135
Dim BizdekiFiyat As String
It returns right results.
110
24
29.5
31.35
There is a problem with decimal records when i want to evaluate this
values..
For example
Dim BizdekiFiyat As String
BizdekiFiyat = BizdekiFiyat * 1.05
It is supposed to be
29.5 * 1.05 =30.975
31.35*1.05=32.9175
but it returns
309,75
3291,75
How can i solve this problem ?"Savas Ates" <in da club> wrote in message
news:OEhAfpwLGHA.648@.TK2MSFTNGP14.phx.gbl...
>I have a column in my table BizdekiFiyat . The datatype = float length =8
>(to save money values).. It is impossible to change these attributes for
>some reasons.
>
> Dim BizdekiFiyat As Integer OR Dim BizdekiFiyat As Decimal
> IT returns
> 110
> 24
> 295
> 3135
Integer datatype will always truncate your decimal fraction values.
I've had data dimension problems trying to use the Decimal datatype for
holding (SQL) decimal data returned through parameters using MS's EntLib
DAAB. I resolved this by using .NET's Double datatype (though I'd prefer to
know why .NET's decimal gave me the problem in the first place).

> Dim BizdekiFiyat As String
> It returns right results.
Because the value is being represented and stored as a string (just like
typing into a textbox), not a numeric type, so...

> There is a problem with decimal records when i want to evaluate this
> values..
> For example
> Dim BizdekiFiyat As String
> BizdekiFiyat = BizdekiFiyat * 1.05
> How can i solve this problem ?
You're expecting .NET to intelligently convert your datatypes for you, which
it is valiantly trying to do. You should consider setting Option Strict on
(Tools | Options | Projects | VB Defaults) to prevent loose data typing and
late binding. You should strongly type your datatypes as a matter of god
practice. When you need to convert datatypes, dothis explicitely using
CType(sourceObj, targetType), or the shorthand versions such as Cint(value),
CDbl(value), etc.
As for your calculations: e.g. using Double to store your values, create a
function which you'll call when necessary to do your calculations:
private function MultiplyBizdekiFiyat(Byval origValue as double, Byval
MultiplyBy as double) As Double
'Perform the calculation
MultiplyBizdekiFiyat = origValue * MultiplyBy
'Return the value to the calling method.
return MultiplyBizdekiFiyat
end function
Hope that helps
Al

Sunday, March 25, 2012

DataSet Update Problem

I know this is very very silly.
But I am stuck and don't know what to do.

I have a simple form which has 1 textbox and a 'Save' button.

I have created a Database connection and an Adapter with Dataset with
the help of Wizards.

I have binded by text box control to one of the database field.

When the form gets loaded it displays the field information correctly.
"Me.SqlDataAdapter1.Fill(DsBasicData1)"

However, when I press the save button it does not update the database
behind it.
I have given the following code to the click event of save button.
"Me.SqlDataAdapter1.Update(DsBasicData1)"

Strangely I don't know why the code does not work.patels (patels@.india.com) writes:
> I know this is very very silly.
> But I am stuck and don't know what to do.
> I have a simple form which has 1 textbox and a 'Save' button.
> I have created a Database connection and an Adapter with Dataset with
> the help of Wizards.
> I have binded by text box control to one of the database field.
> When the form gets loaded it displays the field information correctly.
> "Me.SqlDataAdapter1.Fill(DsBasicData1)"
> However, when I press the save button it does not update the database
> behind it.
> I have given the following code to the click event of save button.
> "Me.SqlDataAdapter1.Update(DsBasicData1)"
>
> Strangely I don't know why the code does not work.

And we don't know your database, or what's in that Update command.
Anyway, I think you should ask about this in a group devoted to
ADO .Net or Visual Studio .Net, as this is not really an
SQL Server issue per se.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Sunday, March 11, 2012

DataGrid DataSet DataAdaptor DataBase problem.

My dataset is not updating my database after the user modifies the datagrid.
I populate my data with the load sub below.
In the Save Sub (below), I have generated my DataSet 'dataSet11' from my
DataAdaptor 'SqlDataAdapter1' and the DataConnection 'SqlConnection1' and
they all seem to be connected correctly. But my data does not update.
the dataAdaptor is configured for Insert/Update/delete and the datagrid
datasource is DataSet11.TableName. Any ideas?
Private Sub Thresholds_Load(ByVal sender As....
Try
cn = New SqlClient.SqlConnection("user id=" & UserName.Text & ";password="
& Password.Text & ";database=" & Database.Text & ";server=" & Server.Text)
cn.Open()
cmdSelect.Connection = cn
Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("Select
* from MISRE_Threshold", cn)
Dim dsThreshold As DataSet = New DataSet
' fill dataset
da.Fill(dsThreshold, "MISRE_Threshold")
'Attach DataSet to DataGrid
dgThreshold.DataSource = dsThreshold.DefaultViewManager
Catch ex As Exception
MessageBox.Show("Error: Could not establish database connection")
End Try
Private Sub btnSave_Click(ByVal sender....
SqlDataAdapter1.Update(DataSet11)
EndSubThe DataAdapter InsertCommand/UpdateCommand/DeleteCommand properties need to
be set in order for the DataAdapter to execute the appropriate commands to
update your table. The SqlCommandBuilder can be used to generate the needed
commands (if you have a primary key) or you can create those the commands
yourself.
Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)
Hope this helps.
Dan Guzman
SQL Server MVP
"marcmc" <marcmc@.discussions.microsoft.com> wrote in message
news:392099C1-6587-46B7-BD60-A20AD3C884AB@.microsoft.com...
> My dataset is not updating my database after the user modifies the
> datagrid.
> I populate my data with the load sub below.
> In the Save Sub (below), I have generated my DataSet 'dataSet11' from my
> DataAdaptor 'SqlDataAdapter1' and the DataConnection 'SqlConnection1' and
> they all seem to be connected correctly. But my data does not update.
> the dataAdaptor is configured for Insert/Update/delete and the datagrid
> datasource is DataSet11.TableName. Any ideas?
> Private Sub Thresholds_Load(ByVal sender As....
> Try
> cn = New SqlClient.SqlConnection("user id=" & UserName.Text &
> ";password="
> & Password.Text & ";database=" & Database.Text & ";server=" & Server.Text)
> cn.Open()
> cmdSelect.Connection = cn
> Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("Select
> * from MISRE_Threshold", cn)
> Dim dsThreshold As DataSet = New DataSet
> ' fill dataset
> da.Fill(dsThreshold, "MISRE_Threshold")
> 'Attach DataSet to DataGrid
> dgThreshold.DataSource = dsThreshold.DefaultViewManager
> Catch ex As Exception
> MessageBox.Show("Error: Could not establish database
> connection")
> End Try
>
> Private Sub btnSave_Click(ByVal sender....
> SqlDataAdapter1.Update(DataSet11)
> EndSub|||They are configured, that's why i'm stumped!
Its the update one i'm interested in as follows:
UPDATE MISRE_Threshold
SET ThresholdType = @.ThresholdType, Threshold = @.Threshold,
Threshold_Flag = @.Threshold_Flag, Actual = @.Actual, Fail = @.Fail,
Category = @.Category, ID = @.ID
WHERE (ThresholdType = @.Original_ThresholdType) AND (Actual =
@.Original_Actual) AND (Category = @.Original_Category OR
@.Original_Category IS NULL AND Category IS NULL) AND
(Fail = @.Original_Fail) AND (ID = @.Original_ID OR
@.Original_ID IS NULL AND ID IS NULL) AND (Threshold =
@.Original_Threshold OR
@.Original_Threshold IS NULL AND Threshold IS NULL) AND
(Threshold_Flag = @.Original_Threshold_Flag OR
@.Original_Threshold_Flag IS NULL AND Threshold_Flag IS
NULL);
SELECT ThresholdType, Threshold,
Threshold_Flag, Actual, Fail, Category, ID
FROM MISRE_Threshold
WHERE (ThresholdType = @.ThresholdType)|||> They are configured, that's why i'm stumped!
The original code you posted instantiates and uses a new untyped dataset:
Dim dsThreshold As DataSet = New DataSet
However, your update routine uses the DataAdapter and DataSet generated by
the windows form designer:
SqlDataAdapter1.Update(DataSet11)
DataSet11 is never filled in the code snippets you posted so it will always
be empty. I believe your intention is to fill DataSet11 in the load
routine:
SqlDataAdapter1.Fill(DataSet11)
Hope this helps.
Dan Guzman
SQL Server MVP
"marcmc" <marcmc@.discussions.microsoft.com> wrote in message
news:E94A87F0-9D2B-4DB1-85E3-5AE7635656DA@.microsoft.com...
> They are configured, that's why i'm stumped!
> Its the update one i'm interested in as follows:
>
> UPDATE MISRE_Threshold
> SET ThresholdType = @.ThresholdType, Threshold = @.Threshold,
> Threshold_Flag = @.Threshold_Flag, Actual = @.Actual, Fail = @.Fail,
> Category = @.Category, ID = @.ID
> WHERE (ThresholdType = @.Original_ThresholdType) AND (Actual =
> @.Original_Actual) AND (Category = @.Original_Category OR
> @.Original_Category IS NULL AND Category IS NULL) AND
> (Fail = @.Original_Fail) AND (ID = @.Original_ID OR
> @.Original_ID IS NULL AND ID IS NULL) AND (Threshold =
> @.Original_Threshold OR
> @.Original_Threshold IS NULL AND Threshold IS NULL)
> AND
> (Threshold_Flag = @.Original_Threshold_Flag OR
> @.Original_Threshold_Flag IS NULL AND Threshold_Flag
> IS
> NULL);
> SELECT ThresholdType, Threshold,
> Threshold_Flag, Actual, Fail, Category, ID
> FROM MISRE_Threshold
> WHERE (ThresholdType = @.ThresholdType)