Showing posts with label sqldatasource. Show all posts
Showing posts with label sqldatasource. Show all posts

Tuesday, March 20, 2012

ConvertEmptyStringToNull

I have a DB table with a varchar field that doesn't allow nulls, but the SqlDataSource I use to update the row wants to put a null in in exchange of an empty string when the field is empty.

<asp:Parameter Name="comment" ConvertEmptyStringToNull="false" Type="string" /
I even tried settting ConvertEmptyStringToNull to "false" but got nowhere.

I can do this by directly by handling the Updating event of the SqlDataSource, but that's a lot of code. Is there a better way?

I don't know whether this is what you are looking for. Use a space for the DefaultValue.

<UpdateParameters>

<asp:ParameterName="comment"DefaultValue=" "Type="String"/></UpdateParameters>|||

You have to set to ConvertEmptyStringToNull="false" on both the Parameter, and the BoundField control.

For example:

<

asp:BoundFieldDataField="locationName"HeaderText="Location Name"SortExpression="locationName"ConvertEmptyStringToNull="false"/>

<

asp:ParameterName="locationName"Type="String"ConvertEmptyStringToNull="false"/>|||

Hi,

This was a great help, I have been teaching myself ASP.NET and it was the first stumbling block. I was following "SAMS Teach Yourself ASP.NET (24Hrs)" and was on the datagrid view section. It was advising me to set the column value (which was set to not allow nulls) to still be able to except a blank entry. This was supposedly achieved by editing the value via the smart tag and then setting the ConvertEmptyStringToNull, which I did. But still failed with the error "Null expected".

I followed the manual method described above and edited the source code and it worked!

My question is if this is a bug with Visual Studio Express? That is the smart tag function is not updating the Parameter. I had to manually edit the source code in order to get it to work as above. Are there other areas that Visual Studio does not via Design view update the source code side of things?

Regards X Smile

|||

Hi exup,

There are a lot of demos showing how complex web pages can be done without digging into code. The problem is that, unless you want your pages to perform exactly like the demos, you will need to dig into code.

"Teach yourself asp.net in 24 hours" as a book title sets up a somewhat unrealistic expectation. Asp.net is complicated, and needs time to master. I'd give yourself a few months to get comfortable with all of the quirks.

John

Thursday, March 8, 2012

Convert SqlDataSource to String.

I'm working with an SqlDataSource, and I'm just wondering how to get the data to a String if I'm sure the select statement will only return 1 piece of data. Any ideas?

useExecuteScalar() method of your sql command. it will return the first column of the first row in the result set return by your select query.

|||

Hi,

You can try to use sqldatasource.select with DataView. Try the codes below, i think it should be able to solve your problems

SqlDataSource1.SelectCommand="Your Select Command Here";DataView dv = SqlDataSource1.Select(DataSourceSelectArguments.Empty);string mystr = dv.Table.Rows[0][your colum number].ToString();

Now the string "mystr" should be what you are looking after

Hope my suggestion helps

Tuesday, February 14, 2012

Convert gridview to report

Dear all,

May I know have anyone try to convert the gridview which bind to a sqldatasource to a report (any kind of report format)?

Thanks

HI

You can export gridview to excel for report, refer toExtensive Study of GridView Export to Excel for details.