Setting Empty Text Box Input On Form To Null Parameter For Sql

Feb 19, 2007

Hi,

 I'm pretty new to ASP.NET and VB, but I'm working on a project which is essentially a staff directory. Using VS 2005, I've setup a basic grid view which connects to an object which connects via a data layer to a SQL database with Name, Surname, Email, Extension No and Department fields.

I have it working so that if a user enters a name and surname for example, it will return all records with either the name matching or surname matching input parameters. What I want to do is to set up a SQL query which is:

 SELECT * FROM records WHERE (Name LIKE @Name) AND (Surname LIKE @Surname) AND (Email LIKE @Email) AND (Dept LIKE @Dept)

so that if the user only enters the first name and surname for example as above, it ONLY returns the record which matches the first name and surname and not all records with either/or. One way I've thought of to do this is to convert the empty fields to "Nothing" so that it fullfils the search parameter for the empty fields. If someone can explain how to do this, or can suggest a better way, I'd be grateful.

Cheers,

Tom

View 3 Replies


ADVERTISEMENT

Parameter Value From Empty Text Box - Null Or 0 Length?

Jul 20, 2005

Hi,I run a stored procedure with a parameter given from a text box in an accessadp. If the text box is empty then what is passed to the parameter? I can'tseem to get it to flag up as either null, or 0 length.Any tips?Cheers,Chris

View 1 Replies View Related

Setting Up Input Form

Oct 24, 2012

The Server / DB that I am trying to connect to is local.Everything is in place, except I do not know what to put in the "data_source" and "Server.MapPath" fields in the 'form_ac.asp' file.It seems like no matter what I put in there (I have tried several different connection strings), that I always get a '500 Internal Server' error as soon as I 'submit' the form. Its like something else is out of place, because it doesn't even seem to check the DB strings (just based on how quickly the 500 error shows up)

You can see the 'test' form I am working with here: URL...And here is the file the form posts to (form_ac.asp):

Code:
<%
' Declaring variables
Dim first, last, account, email, state, comments, data_source, con, sql_insert
' A Function to check if some field entered by user is empty
Function ChkString(string)
ChkString = Replace( Trim(string) , "'", "''")
End Function

[code]....

The bold is where I am having issues. No matter what connection string I try, I keep getting the 500 error in my browser.I have created the Database in SQL Server Management Studio, and created the table.

View 2 Replies View Related

How To Pass Null Value To The Database If A Form Field Is Empty?

May 31, 2004

How can I pass into the database (@User_fax = null) if the fax form field is empty, from a command type Stored Procedure? For example:

Dim CmdUpdate As New SqlCommand("Form2_NewUser", strConnection)
CmdUpdate.CommandType = CommandType.StoredProcedure

CmdUpdate.Parameters.Add("@User_fax", SqlDbType.char, 9)
CmdUpdate.Parameters("@User_fax").Value = fax.Text()

...

strConnection.open()
CmdUpdate.ExecuteNonQuery
strConnection.close()



And, the stored procedure inside Sql server:

USE market1
GO
ALTER PROC Form2_NewUser
@User_id bigint, @User_fax char(9),...

AS

SET NOCOUNT ON
UPDATE Users
SET User_fax = @User_fax, ...

WHERE User_id = @User_id
SET NOCOUNT OFF
GO



Thank you,
Cesar

View 4 Replies View Related

Set Input Parameter To Zero If Null Or Blank

Jan 8, 2015

I am passing few parameters to the sql function to do some calculations. If the input parameter is null or blank, then I want to set the input parameter to the value zero

View 1 Replies View Related

IS NULL Returns Empty Records (using TEXT Type)

Mar 3, 2008

Hi all I am having some issues in selecting items from my database where the record is NOT NULL. I have the code below however although some fields do contain soem data in it, others are blank which I believe are empty spaces. How do I do a SELECT command which ignores empty spaces and NULLS?





Code Snippet

SELECT CustomSearch FROM OfficesTable WHERE CustomSearch IS NOT NULL
Thanks, Onam.

View 10 Replies View Related

Script With If Condition For Multiple Input Parameter That Can Be NULL

Jan 23, 2008

I want to write an Query for a report that has 7 parameters. I want to allow Null for these parameters but at the same time in the Query i want to put an AND condition for all the parameters. I cannot put an OR condition.

For Example;
If i have a report with 2 parameters then the script will have 2* 2 If conditions

something like:-

if( @parameter1 is not Null and @parameter is not Null)
select A, B, C
From Table 1
Where parameter1 = @parameter1 and parameter2 = @prameter2

if( @parameter1 is not Null AND @parameter2 is Null)



select A, B, C
From Table 1
Where parameter1 = @parameter1

If( @parameter1 is Null AND @parameter2 is Not Null)
select A, B, C
From Table 1
Where parameter2 = @parameter2

If( @parameter1 is Null AND @parameter2 is Null)
select A, B, C
From Table 1


For 7 parameter there will be way too many If conditions. Is there an better approch to write a Query for such a situation?

View 11 Replies View Related

Anyway To Check If A Text Field Is Blank (not Null But Just A Empty String '') ?

Oct 27, 2004

i have a trigger on a table right now... when fields are inserted, theres a text field inserted and i want to check if that text field = '' (the empty string, not NULL) and if it doesn't equal that, then perform some row updates on other tables, but if it is empty, to not do anything else in the trigger... right now i have this:


Code:


IF ((SELECT Note FROM XATPoDetail WHERE ReqNbr = (SELECT ReqNbr FROM Inserted)) LIKE(''))



Note is the text field, XATPoDetail is the table where its being inserted into. I had to do the select FROM the table because it wouldn't let me select a text data type from the "Inserted" virtual table

but it tells me me "Error 279: The text, ntext, and image data types are invalid in this subquery or aggregate expression"

thanks

View 2 Replies View Related

Anyway To Check If A Text Field Is Blank (not Null But Just A Empty String '') ?

Oct 27, 2004

i have a trigger on a table right now... when fields are inserted, theres a text field inserted and i want to check if that text field = '' (the empty string, not NULL) and if it doesn't equal that, then perform some row updates on other tables, but if it is empty, to not do anything else in the trigger... right now i have this:


IF ((SELECT Note FROM XATPoDetail WHERE ReqNbr = (SELECT ReqNbr FROM Inserted)) LIKE(''))


Note is the text field, XATPoDetail is the table where its being inserted into. I had to do the select FROM the table because it wouldn't let me select a text data type from the "Inserted" virtual table

but it tells me me "Error 279: The text, ntext, and image data types are invalid in this subquery or aggregate expression"

thanks

View 3 Replies View Related

Empty Form Field Validation?

Dec 24, 2013

I have created a form with basic validation :

if($formValue['forename']=="" || $formValue['surname']=="" || $formValue['username']=="" || $formValue['password']=="" || $formValue['email']=="" ){
$message = "Missing data - please try again" ;
header("Location: registration.php?message=$message");

I want to validate each field individually.

View 1 Replies View Related

Input On Web Form That Updates Sql SERVER

Dec 7, 2005

Can some one give me an over view of what I need to do:

Lets say I have a web form with the field: Arrival Date

A web user enters an arrival date of 2/10/06

How do I do a stored procedure that accepts that arrival date and lets me know (by an alert or email) 24 hrs in advance of the arrival date?

View 2 Replies View Related

Change Not Null To Null, Default Value To Empty

Aug 3, 2005

hi,my structure table in database:Amount float(53) not null default 0when i try to run his script:alter table ABC alter column Amount float(53) nullit can only set the Amount to allow null, but can't set the defaultvalue to empty.anyone know how to set the field to allow null and default set toempty, no value.thanks

View 5 Replies View Related

WITH RETURNS NULL ON NULL INPUT Not Working?

May 3, 2006

Hello.

I've built a sample CLR function with the following declaration....

CREATE FUNCTION GetManager(@DeptCode nvarchar(3))
RETURNS nvarchar(1000)
WITH RETURNS NULL ON NULL INPUT
AS
EXTERNAL NAME Assembly1.[ClassLibrary1.MyVBClass].MyManager

And it works as expected, except when I use NULL:

DECLARE @MyManager nvarchar(1000)
EXEC @MyManager = dbo.GetManager NULL
PRINT @MyManager

It returns the value "Unknown" as it would have for any unknown DeptCode, as-programmed.

I'm of the theory it should have returned NULL without actually firing the function? Or is this only for non-CLR items... or stored procedures, not functions?

View 3 Replies View Related

Insert Query Fails (if Form Fields Left Empty)

Aug 13, 2007

Dear All,
I have created a table in my SQL server database, the problem i am facing is my insert query fails if i leave any form field empty (leave it blank). On my back-end table, only one field is mandatory, and others have been set with the constraint "allow null".
As per our business requirement, except one value is complusory while others are optional. If I enter all values in the form it works perfectly fine. Can you see in the code below - where am i possibly going wrong ?
<script language="VB" runat="server" >      Sub Page_Load(Src As Object, e As EventArgs)                      If Page.IsPostBack Then                        Dim ConLath As SqlConnection            Dim comLath As SqlCommand            Dim insertcmd                        conLath = New SqlConnection("Data Source=SQLas;Initial Catalog=settle;User ID=sa;Password=password")            ConLath.Open()            insertcmd = "Insert into His_set values (@t_d,@s_p,@p_s,@v_oq,@i_oq,@v_qn,@i_qn,@v_qw,@i_qw)"                        comLath = New SqlCommand(insertcmd, ConLath)                                    comLath.Parameters.Add(New SqlParameter("@t_d", SqlDbType.DateTime, 12))            comLath.Parameters("@t_d").Value = trade_date.Text            comLath.Parameters.Add(New SqlParameter("@s_p", SqlDbType.Decimal, 8))            comLath.Parameters("@s_p").Value = sett_price.Text            comLath.Parameters.Add(New SqlParameter("@p_s", SqlDbType.Decimal, 8))            comLath.Parameters("@p_s").Value = post_close.Text            comLath.Parameters.Add(New SqlParameter("@v_oq", SqlDbType.Int, 8))            comLath.Parameters("@v_oq").Value = vol_oq.Text            comLath.Parameters.Add(New SqlParameter("@i_oq", SqlDbType.Int, 8))            comLath.Parameters("@i_oq").Value = oi_oq.Text            comLath.Parameters.Add(New SqlParameter("@v_qn", SqlDbType.Int, 8))            comLath.Parameters("@v_qn").Value = vol_qn.Text            comLath.Parameters.Add(New SqlParameter("@v_qw", SqlDbType.Int, 8))            comLath.Parameters("@v_qw").Value = vol_qw.Text            comLath.Parameters.Add(New SqlParameter("@i_qn", SqlDbType.Int, 8))            comLath.Parameters("@i_qn").Value = oi_qn.Text            comLath.Parameters.Add(New SqlParameter("@i_qw", SqlDbType.Int, 8))            comLath.Parameters("@i_qw").Value = oi_qw.Text
                        Try                comLath.ExecuteNonQuery()                            Catch ex As SqlException                If ex.Number = 2627 Then                    Message.InnerHtml = "ERROR: A record already exists with " _                       & "the same primary key"                Else                    Message.InnerHtml = "ERROR: Could not add record, please " _                       & "ensure the fields are correctly filled out"                    Message.Style("color") = "red"                End If            End Try
            comLath.Dispose()            ConLath.Close()                                                        End If   End Sub
</script>
 

View 6 Replies View Related

Contact Form - Variable Number Of Input Fields, Store Data As Xml String ?

Jul 13, 2007

Im trying to determine the best way to store data gathered from a form that a user will fill out online.  The form is dynamic and is customized at run time based on group-specific criteria.  The end result is a form that might have 3 extra text boxes, 2 extra sets of radio buttons and a freeform textbox, whereas for another group, there might be a slightly different set of input fields.   Now comes the issue of storing this data.  Since the fields can be somewhat dynamic, it could get tricky to define table columns for each possible input field.  So Im considering storing the data as xml.  Has anyone else had to build custom forms and ended up storing the data as xml ?

View 2 Replies View Related

Problem With Text Field: Text Input Too Long, Weird Characters

May 15, 2006

Hi,

Im a programmer for an university webportal which uses php and msssql.
When an user creates a new entry and his text is too long the entry is cut short and weird characters appear at the end of the entry.

For example:
http://www.ttz.uni-magdeburg.de/scripts/test-messedb/php/index.php?option=show_presse&funktion=presse_show_mitteilung&id=333

How can I set the text limit to unlimited?
Could it be something else?
Is there a way of splitting an entry to several text fields automatically?


Thanks in advance for any help you can give me,
Chris

View 3 Replies View Related

My Output Parameter Is Being Treated As An Input Parameter...why

Sep 25, 2006

I have a stored procedure which takes an input parm and is supposed to return an output parameter named NewRetVal.  I have tested the proc from Query Analyzer and it works fine, however when I run the ASP code and do a quickwatch I see that the parm is being switched to an input parm instead of the output parm I have it defined as...any ideas why this is happening?  The update portion works fine, it is the Delete proc that I am having the problems... ASP Code...<asp:SqlDataSource ID="SqlDS_Form" runat="server" ConnectionString="<%$ ConnectionStrings:PTNConnectionString %>" SelectCommand="PTN_sp_getFormDD" SelectCommandType="StoredProcedure" OldValuesParameterFormatString="original_{0}" UpdateCommand="PTN_sp_Form_Update" UpdateCommandType="StoredProcedure" OnUpdated="SqlDS_Form_Updated" OnUpdating="SqlDS_Form_Updating" DeleteCommand="PTN_sp_Form_Del" DeleteCommandType="StoredProcedure" OnDeleting="SqlDS_Form_Updating" OnDeleted="SqlDS_Form_Deleted"><UpdateParameters><asp:ControlParameter ControlID="GridView1" Name="DescID" PropertyName="SelectedValue" Type="Int32" /><asp:ControlParameter ControlID="GridView1" Name="FormNum" PropertyName="SelectedValue" Type="String" /><asp:Parameter Name="original_FormNum" Type="String" /><asp:Parameter Direction="InputOutput" size="25" Name="RetVal" Type="String" /></UpdateParameters><DeleteParameters><asp:Parameter Name="original_FormNum" Type="String" /><asp:Parameter Direction="InputOutput" Size="1" Name="NewRetVal" Type="Int16" /></DeleteParameters></asp:SqlDataSource>Code Behind:protected void SqlDS_Form_Deleted(object sender, SqlDataSourceStatusEventArgs e){  if (e.Exception == null)    {   string strRetVal = (String)e.Command.Parameters["@NewRetVal"].Value.ToString();    ............................Stored Procedure:CREATE PROCEDURE [dbo].[PTN_sp_Form_Del] (
@original_FormNum nvarchar(20),
@NewRetVal INT OUTPUT )
AS
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

DECLARE @stoptrans varchar(5), @AvailFound int, @AssignedFound int

Set @stoptrans = 'NO'

/* ---------------------- Search PART #1 ----------------------------------------------------- */
SET @AvailFound = ( SELECT COUNT(*) FROM dbo.AvailableNumber WHERE dbo.AvailableNumber.FormNum = @original_FormNum )
SET @AssignedFound = ( SELECT COUNT(*) FROM dbo.AssignedNumber WHERE dbo.AssignedNumber.FormNum=@original_FormNum )

IF @AvailFound > 0 OR @AssignedFound > 0 /* It is ok if no rows found on available table, continue on to Assigned table, otherwise stop the deletion.*/
-----This means the delete can't happen...........
BEGIN

IF @AssignedFound > 0 AND @AvailFound = 0
BEGIN
SET @NewRetVal = 1
END

IF @AssignedFound > 0 AND @AvailFound > 0
BEGIN
SET @NewRetVal = 2
END

IF @AssignedFound = 0 AND @AvailFound > 0
BEGIN
SET @NewRetVal = 3
END
END

ELSE
BEGIN
DELETE FROM dbo.Form
WHERE dbo.Form.FormNum=@original_FormNum

SET @NewRetVal = 0
---Successful deletion
END
GO
 --------------------------------------------------------  When I go into the debug mode and do a quickwatch, the NewRetVal is showing as string input.

View 2 Replies View Related

Empty &&<&&> IS NOT NULL

Jul 22, 2007

Hello,



I have a query that returns the appropriate values I need, however there is one field I'd like to add and utilize but my problem is I only want to use it if it contains data.



If I filter it with IS NOT NULL it returns all the records, including the empty records. The field is simply empty, and doesn't come back as NULL. If I filter it with =' ' , it shows all the records with the empty records only.



I need to do the opposite, be able to filter it only if it's not empty.



Any help would be appreciated.

View 4 Replies View Related

Database Level Setting : Allow User Input Chinese Character~

Jul 16, 2007

Dear all,



To allow users enter chinese character into table, I did try to change the field type to nchar and this is workable. But I have few hundred tables.. Is there anyway to change the setting in easier way? by instead change the field type one by one for each table?



I tried change the collation to Chinese_PRC_90_BIN for the database, but it is not support chinese input..



Any Idea?



Thanks.

View 4 Replies View Related

Empty String To Null

Jul 11, 2001

example
create view v_GuestOrder
as
Select T1.id_Guest,T2.OrderName
from Guest T1
left join Order T2 T2.id_order = T1.Id_order


select * from v_GuestOrder
--
Id_Guest OrderName
-------- -----
1 spoon
2 phone
3
4 tv

I need something similar to

Select
id_Guest,
case orderName
when '' then Null -- Sql server gives error in thsi case
end as orderName
from v_GuestOrder

So I need to assign NULL to OrderName is query return empty string,
it will be treated by Crystal reports as Null

Please help , thanks

View 3 Replies View Related

NULL On Empty Fields

Mar 16, 2008

How can I make empty cells show NULL on my table? Some cells show NULL others won't. Does this mean that they have contents?

The reason being is that, when I use the code

Select *
From Employees
Where JobDescription1 Like '%montly%'

Those with empty jobdescription1 show with the legitimate results.

Any help please?

Thanks!

View 2 Replies View Related

COALESCE: Empty Instead Of NULL?

Mar 25, 2008

I've inherited a terribly designed database. When cells in the tables have nothing in them, rather than being NULL, they're just empty. So now I can't use COALESCE...

Is there a way for COALESCE to check if a cell is empty instead of NULL? And if not, is there a way to get around this?

View 1 Replies View Related

Reporting Services :: Give Meaning Full Name To Allow Null Value Check Box In Report Parameter Instead Of NULL?

Oct 20, 2015

In my report i have CNAME parameter , which allows null value. I checked Allow null value check box in report parameter properties.

when i preview the report , it displays checked NULL check box beside CNAME parameter . I want to give some meaningful name(i.e.ALLCustomers) to this checkbox instead of NULL. 

Is it possible through SSRS designer?

View 5 Replies View Related

Database Setting For Text Box And Text Area Forms

Jan 28, 2004

I have a SQL Server database. The data from a table is populated in the table and can do a regular display query on a record without issue.

Problem is when I pull the data into a form the data doesn't show up in some form fields for editing.

I am building a backend for the manager to make updates and changes and this is vital. Does anyone know if it has something to do with a database setting or has had a similar issue in the past?

The reason I think its a database setting is becuase the same table converted into MS Access has no problem populating the text boxs and text areas.

Your help is much needed and appreciated.

Thanks.

View 1 Replies View Related

Form Passing NULL To Database Instead Of Variable

Apr 12, 2007

Not sure what i'm doing wrong here. it seems to be sending nulls or no value to database in places where i want it to send the @headline and @entryhere's the .aspx code: <%@ Page Language="c#"     MasterPageFile="~/MasterPage.master"     AutoEventWireup="true"     CodeFile="NewPost.aspx.cs"     Inherits="NewPost"     Title="Scribbler Insert" %>       <asp:Content ID="PageBody" runat="server"    ContentPlaceHolderID="PageBody" ><table border="0" width="700" >  <tr>    <td width="80" valign="top">      Subject:    </td>    <td width="620" valign="top">      <asp:TextBox ID="txtHeadline" runat="server"           Width="400px"/>      <asp:RequiredFieldValidator runat="server"        ID="RequiredFieldValidator1"        ControlToValidate="txtHeadline"        ErrorMessage="Headline is required"         Display="Dynamic" />    </td>  </tr>  <tr>    <td width="80" valign="top">      Text:    </td>    <td width="620" valign="top">      <asp:TextBox ID="txtEntryText" runat="server"           TextMode="MultiLine"          Height="250px"          Width="400px" />      <asp:RequiredFieldValidator runat="server"        ID="RequiredFieldValidator2"        ControlToValidate="txtEntryText"        ErrorMessage="Text is required"         Display="Dynamic" />    </td>  </tr></table><asp:Button ID="btnPost" runat="server"     Text="Post" OnClick="btnPost_Click" /><asp:Button ID="btnCancel" runat="server"     PostBackUrl="~/Admin/Admin.aspx"     Text="Cancel" />   <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:scribblerdbConnectionString %>"            ProviderName="<%$ ConnectionStrings:scribblerdbConnectionString.ProviderName %>"    InsertCommand="INSERT INTO entries_tbl (Headline, entry, PostedBy, PostedDate, PostedTime) VALUES (@Headline, @Entry, 'SteveP', '2007-12-12', '12:44');" >         <InsertParameters>            <asp:ControlParameter Name="Headline"                ControlID="txtHeadline"                PropertyName="Text"                Type="String" />            <asp:ControlParameter Name="entry"                ControlID="txtEntryText"                PropertyName="Text"                Type="String" />             </InsertParameters></asp:SqlDataSource></asp:Content> 

View 2 Replies View Related

Form Submission Showing Null Values

Apr 13, 2007

I have designed a for to submit some info to a sql database, but when i enter the information to the form fields and click submit, I get an error saying that a null value cannot be submitted, when it should not be null.
Not to sound whiney, but i really need a code fix, not links to msdn pages that define properties (usually dont do this, but i have a deadline to submit this to my tech admin of my company's site)
Here is the code, and THANK YOU to anyone who helps me with this!!
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" %>
<script runat="server">
Private Sub Submitdata(ByVal Source As Object, ByVal e As EventArgs)
SqlDataSource1.Insert()
End Sub ' Submitdata
</script>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
connectionstring="<%$ ConnectionStrings:clientInfoConnectionString %>"
selectcommand="SELECT Client Name,Client Address FROM Clients"
insertcommand="INSERT INTO Clients (ClientName,ClientAddress) VALUES (@CName,@CAddress)">
<insertparameters>
<asp:formparameter name="CName" formfield="Namebox" />
<asp:formparameter name="CAddress" formfield="Addressbox" />
</insertparameters>
</asp:sqldatasource>
&nbsp;Name:<br />
<asp:TextBox ID="Namebox" runat="server" /><br />
 
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Namebox"
ErrorMessage="Please Enter A Name"></asp:RequiredFieldValidator>
 
<br />Address:<br />
<asp:TextBox ID="Addressbox" runat="server" /><br />
 
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Addressbox"
ErrorMessage="Please Enter An Address"></asp:RequiredFieldValidator>
 
<br /><asp:Button ID="Submitbtn" runat="server" Text="Submit" OnClick="Submitdata" />
<br />
 
 
</asp:Content>
Thanks,
The King

View 2 Replies View Related

Store A Null Value Into A Database Coming From A Form

Apr 27, 2007

I have a form and a connectionString to a SQL database. If the textbox at the form is empty i want to store a null value there but when i pass this value as a parameter it brings the following error: Failed to convert parameter value from a String to a Int32..
cmd.Parameters("@Segundo_nombre").Value = txtSecondName.Text.ToString  --> suposing is null it brings an Error.
cmd.Parameters.Add(Apellido)
 How can i manage this? I want to store this value if it is null or not.
Also i don't know how to assign a null value to a variable. I tried with
v_flag = check_selection.check_string(v_idioma)
 
If v_flag = 1 Then 'la variable posee el texto Seleccione
v_idioma = DBNull.Value
but it's not working.
Thanks!!
 

View 1 Replies View Related

Checking If String Is NULL Or EMPTY In SQL

Nov 9, 2007

I need to check in my Stored procedure if the information passed is null or empty so I can decided to insert the new value or keep the old. How do I accomplish this please in T-SQL. Thanks in advance.

View 6 Replies View Related

Insert Empty String Or Null To Sql Db

Jan 12, 2008

Hi:
Trying to insert null value into sql table, but not working, if I use:
 if (strMyText.Length == 0)        command.Parameters.Add("@Text", DBNull.Value); // or using:("@Text", null), or using:("@Text", DBNull) else         command.Parameters.AddWithValue("@Text", strMyText); 
When I go back to table, I see the value is: 'NULL', has single quotation mark, suppose to be: NULL
Where is the problem?
Thanks a lot.
Jt

View 3 Replies View Related

Null, Empty Strings, And Efficiency

Oct 12, 2004

************* Edited by moderator Adec ***************
Inserted missing < code></ code> tags. Always include such
tags when including code in your postings. Don't force the
moderators to do this for you. Many readers disregard
postings without the code tags.
**************************************************

Well met,

Let's say I have a web form that allows users to insert and update records in a SQL database. Is it better to set empty web controls (textbox, etc.) to DBNull or let it go as an empty string into the database?

Example code:

if (tboxNAME.Text == "")
{
sqlCommand1.Parameters["@NAME"].Value = DBNull.Value;
}
else
{
sqlCommand1.Parameters["@NAME"].Value = tboxNAME.Text;
}

Is the above overkill? It seems like it would be a good idea to set fields which the user empties back to Null rather than an empty string.

Thanks,

-Tony

View 2 Replies View Related

Null Or Empty String Use More Space?

Aug 9, 2005

Hi all,   I have some columns in my database which allows null.  I want to know if leaving the field to be NULL or storing an empty string into the field, which will take up more space?? if the field type is varchar(100)

View 5 Replies View Related

HELP : Empty String To Null Conversion By SQL

Nov 10, 2005

Hi folks,

I've have about 100 tables, for some reasons, column values that are originally NULL was inserted as emtpy string. So, I am wondering if I can write JUST ONE SQL (hopefully don't have to specify the field names in the SQL as well) for each table so that all the empty strings will be converted back to NULL.

THANKS JOHN

View 3 Replies View Related

T-SQL (SS2K8) :: Field Has No Value But Is Not NULL Or Empty?

Aug 13, 2015

I added a new field to an existing ETL process which uses SSIS to ingest a CSV file. The new field in the file, Call_Transaction_ID, will not always be populated for every record and so can be NULL or empty for certain records.

Here's the problem:After the file is extracted into a staging table, the Call_Transaction_ID field is showing blank or empty when it has no ID for that particular record. The problem is when I try to then ETL this data into a fact table - I'm trying to set the Call_Transaction_ID field to -1 if it is NULL or empty, however SQL Server doesn't see the field as empty even though there is no value in the field so -1 will NEVER return.

Using a WHERE DATALENGTH(Call_Transaction_ID) = 0 returns 0 records, again because SQL Server doesn't see the field as empty or NULL.

What do I do now to get around this? How do I fix it?

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved