|
Just curious, why are you populating your dataset from SQL Server via XML? It is a most inefficient way of populating a dataset. First SQL Server has to convert its data to XML, send it to your application, which then has to parse the XML and place it in the dataset. It would be much better to use a DataAdapter to populate the DataSet.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
Mr. Mackay;
Many thanks for replying.
I know it is not the best way. The reason, I tried to do this was to test the proof of principle. In order to use the ReadXML method, the command has to bring XML Data and this is the reason for the 'for XML auto' statement.
From the trace, I feel this exception has to do with System.Exception and probably to some 'postback' related problem. I would whether you can point to trouble shoot this.
Thanks
Jay
|
|
|
|
|
Hi all. I've run into an interesting problem. I have a need, with a single selected row in TSql, to count the number of columns with a NULL value (or conversly, the number of columns with a non-null value entered). The table from which the row comes is likely to see changes in its structure over time; adding to the complexity of this need, for simplicity in maintenance, it would be useful not to have to hardcode the column names (I'm thinking of hardcoded "CASE" statements here...)
Does anyone have any suggestions? Ultimately, a user-defined function that, given the primary key value identifying a single row, would return the number of Null values (or non-null values) across the columns in that row would be ideal. I'm hurting my brain on how to get there.
|
|
|
|
|
Greetings,
I have a textbox which I have bound manually (through code) to a database field, and it displays the text correctly. But when I call "myTextBox.Text;" it doesn't have any text found in it, but it shows up on the windows form textbox correctly, but when I call the ".Text" property it isn't there. Is there something I have to manually do to get the text from the bound control?
I am using C# from 2003 studio on a windows xp system, and
here is an example of my code which I called to bind the textbox.
"myTextBox.DataBindings.Add("Text", myDataset1, "TextboxTestField");"
Thanks in advance for any help.
|
|
|
|
|
The only solution I could find on my own was to catch the change text event for the Text box which I had bound to the database field. When the event happened it would just store the text in a member variable which I could then access the actual value.
|
|
|
|
|
I have several DTS packages that each exports a table to a text file. The text files all have a common output folder which I would like to configure using a dynamic properties task.
However, all these packages are executed using another higher level package, and I would like to configure the output folder in this package. How do I communicate the setting to the lower level packages?
My blog.
|
|
|
|
|
I have a textbox (txtPCID), button (btnSearch), and datagrid (DataGrid).
Right now, I want to enter "P0002" in the textbox and click on the search button, I will get all the records which belong to PCID= P0002.
Look at that 4th line.
I don't know why the value in the textbox cannot pass to the sqlCommand?
How to solve it?
Sub BindDataGrid()
Dim Tpcid As String
Tpcid = txtPCID.Text
cmdSql = New SqlCommand("Select * From Peripheral WHERE PCID=' & Tpcid & ' ", myConnection)
myConnection.Open()
DataGrid.DataSource = cmdSql.ExecuteReader()
DataGrid.DataBind()
myConnection.Close()
End Sub
|
|
|
|
|
cmdSql = New SqlCommand("Select * From Peripheral WHERE PCID='"+Tpcid+"' ", myConnection)
I am not sure.. just try once. Sorry if I am wrong. - Sudeep
======
You need a head to program. Cool, fast and sharp.
|
|
|
|
|
You should really parameterise your command. What you have here, if it worked, is suseptable to an injection attack.
cmdSql = New SqlCommand("Select * From Peripheral WHERE PCID=@PCID", myConnection)
cmdSql.Parameters.Add("@PCID",SqlDbType.VarChar, 10).Value = Tpcid
The above is much safer. (Remember to change the SqlDbType and field length values as appropriate)
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
as title.
What is the sql statement?
thanks
|
|
|
|
|
http://www.w3schools.com/sql/sql_select.asp
======
You need a head to program. Cool, fast and sharp.
|
|
|
|
|
A good link
However, i would like to know how to insert char(') into database?
e.g
Insert into table1 values (''','hhhh')
it causes exception
THanks
|
|
|
|
|
this.SqlConnection = new System.Data.SqlClient.SqlConnection();
cmd = new SqlCommand("INSERT INTO TableName (intColumnA, chrColumnB) VALUES (1,'XYX')",this.SqlConnection);
cmd.ExecuteNonQuery();
What exception did you get?
======
Yo need a brain to code.
|
|
|
|
|
sorry
I would know to how to insert the character "'" (single quotation character) into the database varchar field.
Thanks!
|
|
|
|
|
Use 4 apostrophes, one for open string, two for the apostrophe and one for the close string.
If the apostrophe exists in the middle of a string do something like this: 'doesn''t'
Does this help?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
There is way that you can store '
Find and Replace ' by • (Alt+7) and Insert the string in the database. On Retrival Find and Replace • by '
If you using ASP.Net or VB.Net or C# then Finding and Replacing is no Problem
Just Try
String.Replace("'","•");P
|
|
|
|
|
Just create a function that replaces all your ' (single apostrophe) with '' (TWO single apostrophe),
i.e. [Joe O'Connell] becomes [Joe O''Connell]
However, I do recommend using Data Adapters and SQLCommands to pass your parameters so you don't need to worry about this anymore.
It does make my life easier aside from being safer from SQL injection.
|
|
|
|
|
Data Adapters and SQLCommands
What's that?
How to do them?
Thanks!;P
|
|
|
|
|
Insert into table1 values ('''','hhhh')
i.e. replace ' by '' (quote by quote quote)
|
|
|
|
|
hi all,
I am getting following error..
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll. There is no problem with my store procedure as I checked from Query Analyzer.
public static void EditTreatInstrument(int Id,string Name,string BarCode,string PDACode,DateTime ExpireTime,
int Method )
{
SqlCommand cmd = WesServer.GetSqlCommand.Get( Conn , CommandType.StoredProcedure ,
"pr_EditTreatInstrument" );
cmd.Parameters.Add( GetSqlParameter.Get( "@intId", SqlDbType.Int, Id ) );
cmd.Parameters.Add( GetSqlParameter.Get( "@nvchrName", SqlDbType.NVarChar, Name ) );
cmd.Parameters.Add( GetSqlParameter.Get( "@vchrBarCode", SqlDbType.VarChar, BarCode ) );
cmd.Parameters.Add( GetSqlParameter.Get( "@vchrPDACode", SqlDbType.VarChar, PDACode ) );
cmd.Parameters.Add( GetSqlParameter.Get(" @dtExpireDate", SqlDbType.DateTime, ExpireTime ));
cmd.Parameters.Add( GetSqlParameter.Get( "@intMethod", SqlDbType.Int, Method ) );
cmd.ExecuteNonQuery();
}
What are the condition when such error can occer ???
Thanks, Sudeep
======
You need a head to program. Cool, fast and sharp.
|
|
|
|
|
The SqlException object will contain more information.
The Message property and, if multiple error occurred, the Errors property will give lots of good information.
If you cannot see from the exception message then post back to the forum and I'm sure someone will know. Good luck!
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
After doing try catch within the error block I caught such exception:
System.Data.SqlClient.SqlException: @dtExpireDate is not a parameter for procedure pr_EditTreatInstrument. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at.... so on
and when I excluded @dtExpireDate, then I see exception like
System.Data.SqlClient.SqlException: Procedure 'pr_EditTreatInstrument' excepts parameter '@dtExpireDate', which was not supplied. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at... so on
Thank you, Sudee
======
You need a head to program. Cool, fast and sharp.
|
|
|
|
|
I have just noticed a problem in my db with the date format. The problem is that some servers are set to interpret dates differently, eg mm/dd/yy or dd/mm/yy. My problem is to find out which it needs and which to supply. I have also been told that the format of dates is an int, and just adds to 1/1/1900 to get the desired result. I am not sure how this works, but it sounds like it could fix my problem.
If you know of a way that I can parse a date to the db, and it will then decide how to format it, or whatever solution you have in mind, please let me know.
|
|
|
|
|
I just tend to use descriptive method of adding a date to my database.
e.g. "INSERT INTO [MyTable] ([type],[myDate]) VALUES (23, 'Sept 23 2004')"
I then let the DBMS handle everything else. This way there are no confusion over which is the day and which is the month.
|
|
|
|
|
The most reliable and cross-platform compatible way of handling dates that i have found it to use the format "YYYY-MM-DD", optionally "YYYY-MM-DD HH:MM:SS". It's unambiguous, and every DBMS i've used handles it fine.
If you're using MS SQL Server though, you can use any format you like, and remove ambiguity before your query using "set dateformat". see books online for that.
jon
using System.Beer;
|
|
|
|