Showing posts with label row. Show all posts
Showing posts with label row. Show all posts

Friday, March 9, 2012

Problem: Can dhcp callout dll insert new row into dsn database?

I current working on this dll, but i found the dll doesn't response to any of the cdatabase execute response? I have try all the cdatabase and sql in c++ console and found that it can be run. The database is open success and the sql statement is correct.
After then i put it into the dhcp callout dll, and compile success.
When i add it into the registry and try the dhcp server, it doesn't have any response database table. And i using sql server for the dsn.
Here is my code
#include "stdafx.h"
#include "callout.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CDatabase dbCallout;

struct tm *newtime;
char am_pm[] = "AM";
__time64_t long_time;

CString strCmd, strPrimaryKey, strTime;
int nRetCode = 0;

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
} return TRUE;
}

DWORD CALLBACK DhcpControlHook(DWORD dwControlCode,LPVOID lpReserved)
{
switch (dwControlCode)
{
case DHCP_CONTROL_START: {
_time64( &long_time ); /* Get time as long integer. */
newtime = _localtime64(&long_time); /* Convert to local time. */

if( newtime->tm_hour > 12 ) /* Set up extension. */
strcpy( am_pm, "PM" );
if( newtime->tm_hour > 12 ) /* Convert from 24-hour */
newtime->tm_hour -= 12; /* to 12-hour clock. */
if( newtime->tm_hour == 0 ) /*Set hour to 12 if midnight. */
newtime->tm_hour = 12;

strPrimaryKey.Format("C%.2d%.2d%.2d%.2d%.2d%.2d", newtime->tm_year - 100, newtime->tm_mon, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
strTime = asctime(newtime);

strCmd = "INSERT INTO Callout_Control (control_id, control_desc, control_date) VALUES ('" + strPrimaryKey + "', 'DHCP server have started!', '" + strTime + "')";

dbCallout.ExecuteSQL(strCmd);
dbCallout.Close();

break;
}
case DHCP_CONTROL_STOP:
{

break;
}
case DHCP_CONTROL_PAUSE:
{

break;
}
case DHCP_CONTROL_CONTINUE:
{
break;
}
}
return ERROR_SUCCESS;
}

DWORD CALLBACK DhcpServerCalloutEntry(LPWSTR ChainDlls,DWORD CalloutVersion,LPDHCP_CALLOUT_TABLE CalloutTbl)
{

CalloutTbl->DhcpAddressDelHook=DhcpAddressDelHook;
CalloutTbl->DhcpControlHook=DhcpControlHook;
CalloutTbl->DhcpDeleteClientHook=DhcpDeleteClientHook;
CalloutTbl->DhcpPktDropHook=DhcpPktDropHook;
CalloutTbl->DhcpAddressDelHook=DhcpAddressDelHook;
CalloutTbl->DhcpNewPktHook=DhcpNewPktHook;
CalloutTbl->DhcpPktSendHook=DhcpPktSendHook;

dbCallout.Open(_T("CALLOUT"), FALSE, FALSE, _T("ODBC;"));

return ERROR_SUCCESS;
}
What wrong in this code? Can dll file insert new row into dsn? Some expert please help me!!!

Hi

I think your first mitake is that :

1- In DhcpServerCalloutEntry you should set value of CalloutTbl to null if you dont impliment a function

regards

Problem: Can dhcp callout dll insert new row into dsn database?

I current working on this dll, but i found the dll doesn't response to any of the cdatabase execute response? I have try all the cdatabase and sql in c++ console and found that it can be run. The database is open success and the sql statement is correct.
After then i put it into the dhcp callout dll, and compile success.
When i add it into the registry and try the dhcp server, it doesn't have any response database table. And i using sql server for the dsn.
Here is my code
#include "stdafx.h"
#include "callout.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CDatabase dbCallout;

struct tm *newtime;
char am_pm[] = "AM";
__time64_t long_time;

CString strCmd, strPrimaryKey, strTime;
int nRetCode = 0;

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
} return TRUE;
}

DWORD CALLBACK DhcpControlHook(DWORD dwControlCode,LPVOID lpReserved)
{
switch (dwControlCode)
{
case DHCP_CONTROL_START: {
_time64( &long_time ); /* Get time as long integer. */
newtime = _localtime64(&long_time); /* Convert to local time. */

if( newtime->tm_hour > 12 ) /* Set up extension. */
strcpy( am_pm, "PM" );
if( newtime->tm_hour > 12 ) /* Convert from 24-hour */
newtime->tm_hour -= 12; /* to 12-hour clock. */
if( newtime->tm_hour == 0 ) /*Set hour to 12 if midnight. */
newtime->tm_hour = 12;

strPrimaryKey.Format("C%.2d%.2d%.2d%.2d%.2d%.2d", newtime->tm_year - 100, newtime->tm_mon, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
strTime = asctime(newtime);

strCmd = "INSERT INTO Callout_Control (control_id, control_desc, control_date) VALUES ('" + strPrimaryKey + "', 'DHCP server have started!', '" + strTime + "')";

dbCallout.ExecuteSQL(strCmd);
dbCallout.Close();

break;
}
case DHCP_CONTROL_STOP:
{

break;
}
case DHCP_CONTROL_PAUSE:
{

break;
}
case DHCP_CONTROL_CONTINUE:
{
break;
}
}
return ERROR_SUCCESS;
}

DWORD CALLBACK DhcpServerCalloutEntry(LPWSTR ChainDlls,DWORD CalloutVersion,LPDHCP_CALLOUT_TABLE CalloutTbl)
{

CalloutTbl->DhcpAddressDelHook=DhcpAddressDelHook;
CalloutTbl->DhcpControlHook=DhcpControlHook;
CalloutTbl->DhcpDeleteClientHook=DhcpDeleteClientHook;
CalloutTbl->DhcpPktDropHook=DhcpPktDropHook;
CalloutTbl->DhcpAddressDelHook=DhcpAddressDelHook;
CalloutTbl->DhcpNewPktHook=DhcpNewPktHook;
CalloutTbl->DhcpPktSendHook=DhcpPktSendHook;

dbCallout.Open(_T("CALLOUT"), FALSE, FALSE, _T("ODBC;"));

return ERROR_SUCCESS;
}
What wrong in this code? Can dll file insert new row into dsn? Some expert please help me!!!

Hi

I think your first mitake is that :

1- In DhcpServerCalloutEntry you should set value of CalloutTbl to null if you dont impliment a function

regards

Saturday, February 25, 2012

Problem with values returned by Calculated Member

Dear Friends,

I have a problem with CM:

Example

Row Field1 Field2 Field3 Total

1 31662 1 14,75 467014,5

2 250000 1 6,94 1735000

Total for each row= Field1*Field3 / Field2

The value I want for Calculated Member is Total1 + Total 2, 2202014,5, but the value is wrong... The calculated member gives me the value from: SUM Field1* SUM Field3 / SUM Field2, 3054624,39

The MDX:

[Measures].[Open Pos]*[Measures].[New Price]/[Measures].[Fx Rate Rep Cur]

And all the measures are with AggregateFunction as SUM...

Where is the problem? How can I calculate each row in spite of the sum?

Thanks!!

More help to you:

29-12-2006 BANCO PASTOR SA 31662 1 14,75 467.014,50 29-12-2006 GALP ENERGIA SGPS SA B 250000 1 6,94 1.735.000,00

For the date 29.12.2006 I want the calculated member with the value 2202014,5

And currently I'having the value 3054624,39.

|||Is the required calculation Sum(Field 1 * Field 3) / Sum (Field 2)? If so, try adding a calculated column to the DSV that does the (Field 1 * Field 3) calculation. Add this as a new measure, with Sum as the aggregation function. Then your calculated measure will be (New Measure) / (Field 2).|||

for the date 29-12-2006 I need to calculate each line of fact Table...

Example:

Date Field1 Field2 Field3 EachRow 29-12-2006 100 1 5 500 29-12-2006 200 1 4 800 29-12-2006 300 1 2 600 Correct 1900

As I did, in Calculated Member, the value returned is not 1900, but is 2200!! :-(

29-12-2006 600 3 11 2200

Understood?

Thanks!

|||

Then just add the entire calculation ( (Field 1 * Field 3) / Field 2 ) as a calculated column in your DSV. Create a new measure on that column, and set the AggregationFunction to SUM.

Anytime you need something calculated at the fact level, it's usually best to either add it to fact table directly, or include it in the DSV.

|||But field1 is a named calculation, and I cant use this value to create a new named calculation... :-(|||You should be able to replicate the calculation for Field1 in your new calculated column.|||

How can I do it?

When I am creating the second named calculation, in the expression textbox I wrote: [Field1]+1

and returned me the error message: Invalid column named 'Field1'

Field1 is a named calculation... :-(

|||Copy the expression from Field1 into Field2, and add the additional calculations that need to be performed.|||

The problem is that the calculations in named calculation Field 1 is not so simple...

yeh.. but I understood that is no possible call a NC from another NC... thanks!

Problem with values returned by Calculated Member

Dear Friends,

I have a problem with CM:

Example

Row Field1 Field2 Field3 Total

1 31662 1 14,75 467014,5

2 250000 1 6,94 1735000

Total for each row= Field1*Field3 / Field2

The value I want for Calculated Member is Total1 + Total 2, 2202014,5, but the value is wrong... The calculated member gives me the value from: SUM Field1* SUM Field3 / SUM Field2, 3054624,39

The MDX:

[Measures].[Open Pos]*[Measures].[New Price]/[Measures].[Fx Rate Rep Cur]

And all the measures are with AggregateFunction as SUM...

Where is the problem? How can I calculate each row in spite of the sum?

Thanks!!

More help to you:

29-12-2006

BANCO PASTOR SA

31662

1

14,75

467.014,50

29-12-2006

GALP ENERGIA SGPS SA B

250000

1

6,94

1.735.000,00

For the date 29.12.2006 I want the calculated member with the value 2202014,5

And currently I'having the value 3054624,39.

|||Is the required calculation Sum(Field 1 * Field 3) / Sum (Field 2)? If so, try adding a calculated column to the DSV that does the (Field 1 * Field 3) calculation. Add this as a new measure, with Sum as the aggregation function. Then your calculated measure will be (New Measure) / (Field 2).|||

for the date 29-12-2006 I need to calculate each line of fact Table...

Example:

Date

Field1

Field2

Field3

EachRow

29-12-2006

100

1

5

500

29-12-2006

200

1

4

800

29-12-2006

300

1

2

600

Correct

1900

As I did, in Calculated Member, the value returned is not 1900, but is 2200!! :-(

29-12-2006

600

3

11

2200

Understood?

Thanks!

|||

Then just add the entire calculation ( (Field 1 * Field 3) / Field 2 ) as a calculated column in your DSV. Create a new measure on that column, and set the AggregationFunction to SUM.

Anytime you need something calculated at the fact level, it's usually best to either add it to fact table directly, or include it in the DSV.

|||But field1 is a named calculation, and I cant use this value to create a new named calculation... :-(|||You should be able to replicate the calculation for Field1 in your new calculated column.|||

How can I do it?

When I am creating the second named calculation, in the expression textbox I wrote: [Field1]+1

and returned me the error message: Invalid column named 'Field1'

Field1 is a named calculation... :-(

|||Copy the expression from Field1 into Field2, and add the additional calculations that need to be performed.|||

The problem is that the calculations in named calculation Field 1 is not so simple...

yeh.. but I understood that is no possible call a NC from another NC... thanks!

Monday, February 20, 2012

Problem with updating only one row in a SQL 2005 database

hi,

I have a problem with updating a row in my database. I don't know how to update and i need help.

I have a form where the users select a category and a sub category to enter a message.

I have two dropdown lists, one is for selecting the category and the other is for the sub-category.

In my database for the categories and the sub-categories, i have a variable (Quantity) where i keep the quantity for each table.

I just want to be able to increment this variable by 1 (for the selected category and sub-category) when a user enter a new message...

The insert procedure is working well and have no problem with it.

I use VWD 2005 Express with SQL 2005 express and i code in VB.

HELP!!!!!

Please post your table structure, some sample data and the update you are expecting to happen. Also the query you currently have would help.

|||

ok


Table Categories
------
CategoryID / int / Primary key
CategoryName / varchar(50)
Description / varchar (50)
Quantity / int

Table SubCategories
------
SubCategoryID / int / Primary key
CategoryID / int / Foreign key, linked to Table Categories-CategoryID
SubCategoryName / varchar(50)
Description / varchar (50)
Quantity / int


So when a user post a message, i want that the Quantity for table Categories and SubCategories increment by 1.


Portion of my code :
-------

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="CategoryName" DataValueField="CategoryID">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:databaseDB %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories] ORDER BY [CategoryName]">
</asp:SqlDataSource>

<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource2"
DataTextField="SousCategoryName" DataValueField="SubCategoryID" AutoPostBack="True">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:databaseDB %>"
SelectCommand="SELECT [SubCategoryID], [SubCategoryName] FROM [SousCategories] WHERE ([CategoryID] = @.CategoryID) ORDER BY [SubCategoryName]">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="CategoryID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

|||

With corrections!

----------

ok


Table Categories
------
CategoryID / int / Primary key
CategoryName / varchar(50)
Description / varchar (50)
Quantity / int

Table SubCategories
------
SubCategoryID / int / Primary key
CategoryID / int / Foreign key, linked to Table Categories-CategoryID
SubCategoryName / varchar(50)
Description / varchar (50)
Quantity / int


So when a user post a message, i want that the Quantity for table Categories and SubCategories increment by 1.


Portion of my code :
-------

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="CategoryName" DataValueField="CategoryID">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:databaseDB %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories] ORDER BY [CategoryName]">
</asp:SqlDataSource>

<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource2"
DataTextField="SubCategoryName" DataValueField="SubCategoryID" AutoPostBack="True">
</asp:DropDownList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:databaseDB %>"
SelectCommand="SELECT [SubCategoryID], [SubCategoryName] FROM [SubCategories] WHERE ([CategoryID] = @.CategoryID) ORDER BY [SubCategoryName]">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="CategoryID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

|||So any ideas?|||

Hi,

You can create a button_click event in your code-behind page. The following code (c#) is just a sample which can achieve your purpose.

protected void Button1_Click(object sender, EventArgs e) {/// Get the CategoryName value from DropDownList1string CategoryName =this.DropDownList1.SelectedItem.Value;/// Get the CategoryName value from DropDownList2string SubCategoryName =this.DropDownList2.SelectedItem.Value;/// in this sample,we get the message and the username value from textboxesstring Message =this.TextBox1.Text;string User=this.TextBox2.Text;/// connstr is the name of connection string you set in Web.configstring conn = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString; SqlConnection myconn =new SqlConnection(conn);/// write the message which user submit into YourTablestring insert_command ="Insert into YourTable (CategoryName,SubCategoryName,Message,Users) values('"+CategoryName+"','"+SubCategoryName+"','"+Message+"','"+User+"')"; myconn.Open(); SqlCommand mycomm =new SqlCommand(insert_command, myconn); mycomm.ExecuteNonQuery(); mycomm.Dispose();/// sql for updating the Quantity number in the Categories tablestring up_cate ="update Categories set Quantity = (Quantity+1) where CategoryName = '" + CategoryName +"'";/// sql for updating the Quantity number in the SubCategories tablestring up_subcate ="update SubCategories set Quantity = (Quantity+1) where SubCategoryName ='" + SubCategoryName +"'"; SqlCommand mycomm_1 =new SqlCommand(up_cate, myconn); SqlCommand mycomm_2 =new SqlCommand(up_subcate, myconn); mycomm_1.ExecuteNonQuery(); mycomm_2.ExecuteNonQuery(); mycomm_1.Dispose(); mycomm_2.Dispose(); myconn.Close(); }
Hope it helps. Thanks.|||

Sorry i code in VB...

I tried that and it's not working (on a click event) :

Dim myConnection As String = System.Configuration.ConfigurationManager.ConnectionStrings("FouinerDB").ConnectionString
Dim myConnectionDB As New Data.SqlClient.SqlConnection(myConnection)
Dim myDA As New Data.SqlClient.SqlDataAdapter()

Dim CatID As Integer = ddlCategories.SelectedValue
Dim SubCatID As Integer = ddlSousCategories.SelectedValue

myDA.UpdateCommand = New Data.SqlClient.SqlCommand("UPDATE Categories SET Quantity=10 WHERE CategoryID = " & CatID.ToString(), myConnectionDB)

|||

(1) Please use parameterized queries to prevent SQL injeection attacks.

I would recommend you do it via stored procedure as follows:

Update CategoriesSET Quantity = Quantity + 1WHERE Categoryid = @.CategoryidUpdate SubCategoriesSET Quantity = Quantity + 1WHERE SubCategories = @.SubCategoriesand Categoryid = @.Categoryid

If you had to do it via adhoc T-SQL, you'd be making 2 trips once for each Update. Through a stored proc, you can do it all in one trip.

|||Ok, but how do you call the stored procedure in the vb code.

I dont know nothing about it... ;-(|||I tired that for stored procedure and when i try it (execute), it doesn't change anything in my database (i also tried to change @.Categoryid and @.SousCategoriesID by values that i know are valid ) :

ALTER PROCEDURE

dbo.UpdateQuantity/*(@.parameter1 int = 5,@.parameter2 datatype OUTPUT)*/

AS

/* SET NOCOUNT ON */RETURN

BEGIN

DECLARE@.CategoryidintDECLARE@.SousCategoriesIDint

UPDATE

CategoriesSETQuantity = Quantity + 1WHERECategoryID = @.Categoryid

UPDATE

SousCategoriesSETQuantity = Quantity + 1WHERESousCategoriesID = @.SousCategoriesID

END

|||I don't understand why aSelectCommand works in my page and not anUpdateCommand...

Works!!!
myDA.SelectCommand =

New Data.SqlClient.SqlCommand("SELECT * FROM Annonces WHERE SousCategoryID = " & SubCatID.ToString(), myConnectionDB)

Dont works!!!
myDA.UpdateCommand =New Data.SqlClient.SqlCommand("UPDATE Categories SET Quantity = 10 WHERE CategoryID = " & CatID.ToString(), myConnectionDB)
|||

Ok i finally got it!!!

It's theUpdateCommand.ExecuteNonQuery() that i missed. ;-)

I will also try with a Stored Procedure... See you soon!
-----------

Dim myConnection As String = System.Configuration.ConfigurationManager.ConnectionStrings("DatabaseDB").ConnectionString
Dim myConnectionDB As New Data.SqlClient.SqlConnection(myConnection)
myConnectionDB.Open()
Dim myDA1 As New Data.SqlClient.SqlDataAdapter()
Dim myDA2 As New Data.SqlClient.SqlDataAdapter()

Dim CatID As Integer = ddlCategories.SelectedValue
Dim SubCatID As Integer = ddlSousCategories.SelectedValue

myDA1.UpdateCommand = New Data.SqlClient.SqlCommand("UPDATE Categories SET Quantity = Quantity + 1 WHERE CategoryID = " & CatID.ToString(), myConnectionDB)
myDA2.UpdateCommand = New Data.SqlClient.SqlCommand("UPDATE SousCategories SET Quantity = Quantity + 1 WHERE SousCategoriesID = " & SubCatID.ToString(), myConnectionDB)
myDA1.UpdateCommand.ExecuteNonQuery()
myDA2.UpdateCommand.ExecuteNonQuery()
myConnectionDB.Close()

|||

It would be more like this: The parameters values would come from your VB application. For your update on SubCategories I also added the CategoryId= @.CategoryID condition because I assumed that the same subcategory could be present for multiple categories. So its important to also specify the Category level.

ALTER PROCEDURE dbo.UpdateQuantity ( @.Categoryidint , @.SousCategoriesIDinT)ASBeginSET NOCOUNT ON UPDATE CategoriesSET Quantity = Quantity + 1WHERE CategoryID = @.CategoryidUPDATE SousCategoriesSET Quantity = Quantity + 1WHERE SousCategoriesID = @.SousCategoriesIDAnd CategoryID = @.CategoryidSET NOCOUNT OFFEND

Your VB code could look like this:

Dim myCommandAs SqlCommandDim myParamAs SqlParametermyCommand =New SqlCommand()myCommand.Connection = objconmyCommand.CommandText ="updateQuantity"myCommand.CommandType = CommandType.StoredProceduremyCommand.Parameters.Add(New SqlParameter("@.Categoryid",SqlDbType.int))myCommand.Parameters("@.Categoryid").Value = 10myCommand.Parameters.Add(New SqlParameter("@.SousCategoriesID",SqlDbType.int))myCommand.Parameters("@.SousCategoriesID").Value = 1TryIf objCon.State = 0Then objCon.Open()mycommand.ExecuteNonQuery()Catch excAs ExceptionResponse.Write(exc)FinallyIf objCon.State = ConnectionState.OpenThen objCon.Close()End IfEnd Try

|||Hi,

In terms of process speed, wich one is the fastest?

Hard coding or Stored Procedure?|||

Whether you use T-SQL/stored proc the actual statements are executed at the DB. IF you had multiple T-SQL statements to be executed you are better off using stored procs as you can do it all in one trip. Also, if you have T-SQL all over your app it becomes a maintenance nightmare if your underlying schema changes in future. Stored procs provide a channelized way of accesssing the data. Also, for security reasons procs are a better choice. You'd have to give SELECT/UPDATE/DELETE rights to the userid you are using on the actual table if you use adhoc queries. If you do the same thing via procs, you just give the user permission to execute the proc. There are tons of other pros vs cons. You can also google (adhoc query vs stored proc) and see some good debate about this.

Problem with update when updating all rows of a table through dataset and saving back to d

Hi,

I have an application where I'm filling a dataset with values from a table. This table has no primary key. Then I iterate through each row of the dataset and I compute the value of one of the columns and then update that value in the dataset row. The problem I'm having is that when the database gets updated by the SqlDataAdapter.Update() method, the same value shows up under that column for all rows. I think my Update Command is not correct since I'm not specifying a where clause and hence it is using just the value lastly computed in the dataset to update the entire database. But I do not know how to specify a where clause for an update statement when I'm actually updating every row in the dataset. Basically I do not have an update parameter since all rows are meant to be updated. Any suggestions?

SqlCommand snUpdate = conn.CreateCommand();

snUpdate.CommandType =CommandType.Text;

snUpdate.CommandText ="Update TestTable set shipdate = @.shipdate";

snUpdate.Parameters.Add("@.shipdate",SqlDbType.Char, 10,"shipdate");

string jdate ="";

for (int i = 0; i < ds.Tables[0].Rows.Count - 1; i++)

{

jdate = ds.Tables[0].Rows[i]["shipdate"].ToString();

ds.Tables[0].Rows[i]["shipdate"] = convertToNormalDate(jdate);

}

da.Update(ds,"Table1");

conn.Close();

-Thanks

a quick once over and i have a few questions--what all in your TestTable? Also in all lines of code you refer to your table as Tables[0] you should always stick to one way. Your right about your Update, so when we see what's in your TestTable we'll be able to help you out a little bit more.

|||

Thanks for your response. My table contains 2 fields SKU numbers and Ship Dates. I changed my update statement as follows and it worked.

snUpdate.CommandText ="Update TestTable set shipdate = @.shipdate where skunum=@.skunum";

snUpdate.Parameters.Add("@.shipdate",SqlDbType.Char, 10,"shipdate");

snUpdate.Parameters.Add("@.skunum",SqlDbType.Int, 4,"skunum");

snUpdate.Parameters["@.skunum"].SourceVersion =DataRowVersion.Original;

-Thanks

|||So is skunum a unique value? If not, then it'll update all rows with that skunum. If it is, then why isn't that your primary key?|||The skunum is not unique. The table does have some duplicated data which I don't have to worry about if they get updated with the same value. This is just an old table whose data will be transformed into a different table and used in an app after my updates are done. Thanks.

Problem With Update Unicode Field

Hello.
I have a problem with update Unicode field in MS SQL Server 2000.
When I insert new row into the table and fill some Unicode field with some
data it's working fine, but when I try to update existing record with some
new values in Unicode fields the data is displaying as "?" symbols.
Can anybody tell me how can I solve this problem?A table definition and the update statement would be helpful.
A quick example that may be helpful to you:
CREATE TABLE Frog (
UnicodeColumn nvarchar(50),
ANSIColumn varchar(50)
)
GO
INSERT FROG VALUES (N'Some Unicode Data goes here', 'ANSI data here')
GO
SELECT * FROM Frog
GO
UPDATE Frog
SET UnicodeColumn = N'Other Unicode Data'
GO
SELECT * FROM Frog
GO
-- Notice the N in front of the Unicode data segment. This tells SQL Server
that "National" character data follows.
HTH
Rick Sawtell
"David" <david_dvali@.hotmail.com> wrote in message
news:OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl...
> Hello.
> I have a problem with update Unicode field in MS SQL Server 2000.
> When I insert new row into the table and fill some Unicode field with some
> data it's working fine, but when I try to update existing record with some
> new values in Unicode fields the data is displaying as "?" symbols.
> Can anybody tell me how can I solve this problem?
>|||How can I use 'N' in parametrized SQL?
"Rick Sawtell" <r_sawtell@.hotmail.com> wrote in message
news:e9gN9P3bEHA.4092@.TK2MSFTNGP11.phx.gbl...
> A table definition and the update statement would be helpful.
> A quick example that may be helpful to you:
> CREATE TABLE Frog (
> UnicodeColumn nvarchar(50),
> ANSIColumn varchar(50)
> )
> GO
>
> INSERT FROG VALUES (N'Some Unicode Data goes here', 'ANSI data here')
> GO
> SELECT * FROM Frog
> GO
> UPDATE Frog
> SET UnicodeColumn = N'Other Unicode Data'
> GO
> SELECT * FROM Frog
> GO
>
> -- Notice the N in front of the Unicode data segment. This tells SQL
Server
> that "National" character data follows.
>
> HTH
> Rick Sawtell
>
> "David" <david_dvali@.hotmail.com> wrote in message
> news:OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl...
some[vbcol=seagreen]
some[vbcol=seagreen]
>|||You don't need to use the N if you are passing your data in RPC parameters.
What API are you using? When you define the parameter are you setting it
up as a Unicode param? A bit of sample code showing how you pass your data
in might help.
Bart
--
Bart Duncan
Microsoft SQL Server Support
Please reply to the newsgroup only - thanks.
This posting is provided "AS IS" with no warranties, and confers no rights.
| Reply-To: "David" <david_dvali@.hotmail.com>
| From: "David" <david_dvali@.hotmail.com>
| References: <OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl>
<e9gN9P3bEHA.4092@.TK2MSFTNGP11.phx.gbl>
| Subject: Re: Problem With Update Unicode Field
| Date: Thu, 22 Jul 2004 13:41:26 +0400
| Lines: 59
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <eX60aB9bEHA.4032@.TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.sqlserver.server
| NNTP-Posting-Host: ge-tbs-ats77-tc-ppp12.wanex.net 213.131.38.173
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.sqlserver.server:352505
| X-Tomcat-NG: microsoft.public.sqlserver.server
|
| How can I use 'N' in parametrized SQL?
|
| "Rick Sawtell" <r_sawtell@.hotmail.com> wrote in message
| news:e9gN9P3bEHA.4092@.TK2MSFTNGP11.phx.gbl...
| > A table definition and the update statement would be helpful.
| >
| > A quick example that may be helpful to you:
| >
| > CREATE TABLE Frog (
| > UnicodeColumn nvarchar(50),
| > ANSIColumn varchar(50)
| > )
| > GO
| >
| >
| > INSERT FROG VALUES (N'Some Unicode Data goes here', 'ANSI data here')
| > GO
| >
| > SELECT * FROM Frog
| > GO
| >
| > UPDATE Frog
| > SET UnicodeColumn = N'Other Unicode Data'
| > GO
| >
| > SELECT * FROM Frog
| > GO
| >
| >
| > -- Notice the N in front of the Unicode data segment. This tells SQL
| Server
| > that "National" character data follows.
| >
| >
| > HTH
| >
| > Rick Sawtell
| >
| >
| >
| > "David" <david_dvali@.hotmail.com> wrote in message
| > news:OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl...
| > > Hello.
| > >
| > > I have a problem with update Unicode field in MS SQL Server 2000.
| > >
| > > When I insert new row into the table and fill some Unicode field with
| some
| > > data it's working fine, but when I try to update existing record with
| some
| > > new values in Unicode fields the data is displaying as "?" symbols.
| > >
| > > Can anybody tell me how can I solve this problem?
| > >
| > >
| >
| >
|
|
|

Problem With Update Unicode Field

Hello.
I have a problem with update Unicode field in MS SQL Server 2000.
When I insert new row into the table and fill some Unicode field with some
data it's working fine, but when I try to update existing record with some
new values in Unicode fields the data is displaying as "?" symbols.
Can anybody tell me how can I solve this problem?A table definition and the update statement would be helpful.
A quick example that may be helpful to you:
CREATE TABLE Frog (
UnicodeColumn nvarchar(50),
ANSIColumn varchar(50)
)
GO
INSERT FROG VALUES (N'Some Unicode Data goes here', 'ANSI data here')
GO
SELECT * FROM Frog
GO
UPDATE Frog
SET UnicodeColumn = N'Other Unicode Data'
GO
SELECT * FROM Frog
GO
-- Notice the N in front of the Unicode data segment. This tells SQL Server
that "National" character data follows.
HTH
Rick Sawtell
"David" <david_dvali@.hotmail.com> wrote in message
news:OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl...
> Hello.
> I have a problem with update Unicode field in MS SQL Server 2000.
> When I insert new row into the table and fill some Unicode field with some
> data it's working fine, but when I try to update existing record with some
> new values in Unicode fields the data is displaying as "?" symbols.
> Can anybody tell me how can I solve this problem?
>|||How can I use 'N' in parametrized SQL?
"Rick Sawtell" <r_sawtell@.hotmail.com> wrote in message
news:e9gN9P3bEHA.4092@.TK2MSFTNGP11.phx.gbl...
> A table definition and the update statement would be helpful.
> A quick example that may be helpful to you:
> CREATE TABLE Frog (
> UnicodeColumn nvarchar(50),
> ANSIColumn varchar(50)
> )
> GO
>
> INSERT FROG VALUES (N'Some Unicode Data goes here', 'ANSI data here')
> GO
> SELECT * FROM Frog
> GO
> UPDATE Frog
> SET UnicodeColumn = N'Other Unicode Data'
> GO
> SELECT * FROM Frog
> GO
>
> -- Notice the N in front of the Unicode data segment. This tells SQL
Server
> that "National" character data follows.
>
> HTH
> Rick Sawtell
>
> "David" <david_dvali@.hotmail.com> wrote in message
> news:OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl...
> > Hello.
> >
> > I have a problem with update Unicode field in MS SQL Server 2000.
> >
> > When I insert new row into the table and fill some Unicode field with
some
> > data it's working fine, but when I try to update existing record with
some
> > new values in Unicode fields the data is displaying as "?" symbols.
> >
> > Can anybody tell me how can I solve this problem?
> >
> >
>|||You don't need to use the N if you are passing your data in RPC parameters.
What API are you using? When you define the parameter are you setting it
up as a Unicode param? A bit of sample code showing how you pass your data
in might help.
Bart
--
Bart Duncan
Microsoft SQL Server Support
Please reply to the newsgroup only - thanks.
This posting is provided "AS IS" with no warranties, and confers no rights.
| Reply-To: "David" <david_dvali@.hotmail.com>
| From: "David" <david_dvali@.hotmail.com>
| References: <OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl>
<e9gN9P3bEHA.4092@.TK2MSFTNGP11.phx.gbl>
| Subject: Re: Problem With Update Unicode Field
| Date: Thu, 22 Jul 2004 13:41:26 +0400
| Lines: 59
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <eX60aB9bEHA.4032@.TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.sqlserver.server
| NNTP-Posting-Host: ge-tbs-ats77-tc-ppp12.wanex.net 213.131.38.173
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.sqlserver.server:352505
| X-Tomcat-NG: microsoft.public.sqlserver.server
|
| How can I use 'N' in parametrized SQL?
|
| "Rick Sawtell" <r_sawtell@.hotmail.com> wrote in message
| news:e9gN9P3bEHA.4092@.TK2MSFTNGP11.phx.gbl...
| > A table definition and the update statement would be helpful.
| >
| > A quick example that may be helpful to you:
| >
| > CREATE TABLE Frog (
| > UnicodeColumn nvarchar(50),
| > ANSIColumn varchar(50)
| > )
| > GO
| >
| >
| > INSERT FROG VALUES (N'Some Unicode Data goes here', 'ANSI data here')
| > GO
| >
| > SELECT * FROM Frog
| > GO
| >
| > UPDATE Frog
| > SET UnicodeColumn = N'Other Unicode Data'
| > GO
| >
| > SELECT * FROM Frog
| > GO
| >
| >
| > -- Notice the N in front of the Unicode data segment. This tells SQL
| Server
| > that "National" character data follows.
| >
| >
| > HTH
| >
| > Rick Sawtell
| >
| >
| >
| > "David" <david_dvali@.hotmail.com> wrote in message
| > news:OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl...
| > > Hello.
| > >
| > > I have a problem with update Unicode field in MS SQL Server 2000.
| > >
| > > When I insert new row into the table and fill some Unicode field with
| some
| > > data it's working fine, but when I try to update existing record with
| some
| > > new values in Unicode fields the data is displaying as "?" symbols.
| > >
| > > Can anybody tell me how can I solve this problem?
| > >
| > >
| >
| >
|
|
|

Problem With Update Unicode Field

Hello.
I have a problem with update Unicode field in MS SQL Server 2000.
When I insert new row into the table and fill some Unicode field with some
data it's working fine, but when I try to update existing record with some
new values in Unicode fields the data is displaying as "?" symbols.
Can anybody tell me how can I solve this problem?
A table definition and the update statement would be helpful.
A quick example that may be helpful to you:
CREATE TABLE Frog (
UnicodeColumn nvarchar(50),
ANSIColumn varchar(50)
)
GO
INSERT FROG VALUES (N'Some Unicode Data goes here', 'ANSI data here')
GO
SELECT * FROM Frog
GO
UPDATE Frog
SET UnicodeColumn = N'Other Unicode Data'
GO
SELECT * FROM Frog
GO
-- Notice the N in front of the Unicode data segment. This tells SQL Server
that "National" character data follows.
HTH
Rick Sawtell
"David" <david_dvali@.hotmail.com> wrote in message
news:OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl...
> Hello.
> I have a problem with update Unicode field in MS SQL Server 2000.
> When I insert new row into the table and fill some Unicode field with some
> data it's working fine, but when I try to update existing record with some
> new values in Unicode fields the data is displaying as "?" symbols.
> Can anybody tell me how can I solve this problem?
>
|||How can I use 'N' in parametrized SQL?
"Rick Sawtell" <r_sawtell@.hotmail.com> wrote in message
news:e9gN9P3bEHA.4092@.TK2MSFTNGP11.phx.gbl...
> A table definition and the update statement would be helpful.
> A quick example that may be helpful to you:
> CREATE TABLE Frog (
> UnicodeColumn nvarchar(50),
> ANSIColumn varchar(50)
> )
> GO
>
> INSERT FROG VALUES (N'Some Unicode Data goes here', 'ANSI data here')
> GO
> SELECT * FROM Frog
> GO
> UPDATE Frog
> SET UnicodeColumn = N'Other Unicode Data'
> GO
> SELECT * FROM Frog
> GO
>
> -- Notice the N in front of the Unicode data segment. This tells SQL
Server[vbcol=seagreen]
> that "National" character data follows.
>
> HTH
> Rick Sawtell
>
> "David" <david_dvali@.hotmail.com> wrote in message
> news:OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl...
some[vbcol=seagreen]
some
>
|||You don't need to use the N if you are passing your data in RPC parameters.
What API are you using? When you define the parameter are you setting it
up as a Unicode param? A bit of sample code showing how you pass your data
in might help.
Bart
Bart Duncan
Microsoft SQL Server Support
Please reply to the newsgroup only - thanks.
This posting is provided "AS IS" with no warranties, and confers no rights.
| Reply-To: "David" <david_dvali@.hotmail.com>
| From: "David" <david_dvali@.hotmail.com>
| References: <OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl>
<e9gN9P3bEHA.4092@.TK2MSFTNGP11.phx.gbl>
| Subject: Re: Problem With Update Unicode Field
| Date: Thu, 22 Jul 2004 13:41:26 +0400
| Lines: 59
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <eX60aB9bEHA.4032@.TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.sqlserver.server
| NNTP-Posting-Host: ge-tbs-ats77-tc-ppp12.wanex.net 213.131.38.173
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFT NGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.sqlserver.server:352505
| X-Tomcat-NG: microsoft.public.sqlserver.server
|
| How can I use 'N' in parametrized SQL?
|
| "Rick Sawtell" <r_sawtell@.hotmail.com> wrote in message
| news:e9gN9P3bEHA.4092@.TK2MSFTNGP11.phx.gbl...
| > A table definition and the update statement would be helpful.
| >
| > A quick example that may be helpful to you:
| >
| > CREATE TABLE Frog (
| > UnicodeColumn nvarchar(50),
| > ANSIColumn varchar(50)
| > )
| > GO
| >
| >
| > INSERT FROG VALUES (N'Some Unicode Data goes here', 'ANSI data here')
| > GO
| >
| > SELECT * FROM Frog
| > GO
| >
| > UPDATE Frog
| > SET UnicodeColumn = N'Other Unicode Data'
| > GO
| >
| > SELECT * FROM Frog
| > GO
| >
| >
| > -- Notice the N in front of the Unicode data segment. This tells SQL
| Server
| > that "National" character data follows.
| >
| >
| > HTH
| >
| > Rick Sawtell
| >
| >
| >
| > "David" <david_dvali@.hotmail.com> wrote in message
| > news:OwBu3y1bEHA.1132@.TK2MSFTNGP10.phx.gbl...
| > > Hello.
| > >
| > > I have a problem with update Unicode field in MS SQL Server 2000.
| > >
| > > When I insert new row into the table and fill some Unicode field with
| some
| > > data it's working fine, but when I try to update existing record with
| some
| > > new values in Unicode fields the data is displaying as "?" symbols.
| > >
| > > Can anybody tell me how can I solve this problem?
| > >
| > >
| >
| >
|
|
|