DataSource Controls :: Null Datasource - Forward To New Page
Jan 19, 2010
I have page that has a datasource. The datasource executes a stored procedure and returns results. If the result is NULL, I'd like to forward the user to an error page. How would I accomplish this with ASP.NET and C#?
i have problem white Object datasource. i have a multi-tier Application that include common layer ,DAL Layer,business logic and persantation layerwhen i add a object datasource to my page, it bring me only common layer classes . but i want use bisuiness layer classes what do i do ?
here is my code for selectiong some records from db table
string strSql = "select * from mtblNBD where SentTo=@SentTo and InternalStatus Is NULL order by DeadLine desc"; SqlCommand com = new SqlCommand(strSql, con); com.Parameters.Add("@SentTo", SqlDbType.NVarChar, 50).Value = (string)Session["uname"];
here I am using parameters for SenTo field but not for NULL so it is ok... or should I use parameters for this field where value is NULL , if yes then how can I use parameter for this
I need to retrive a value from a column of a table per stored proc. This is usually an integer, but also can be null. I get this value and store it in a session variable.
Later, I need to pass this same session variable to another stored proc.
Session["myVariable"] = ds.tables[0].rows[0][1]; // this can be null or an integer
somewhere else in the project, I need to pass it to another stored proc exactly as received.
here is my update query syntax.my problem is.if i update only logo1 and logo3 with null logo2 and img null then my query should be update the other record.just dont update null value record but other should be update.but below my query can not update any record.
UPDATE tbitem set itemname= @itemname,note=@note, price=@price,qty=@qty,logo1=@logo1, logo2=@logo2,logo3=@logo3,img=@img where id =@id and @logo1 is null and @logo2 is null and @logo3 is null and @img is null
I get a recordset returned from DB and try to load it. However sometimes field "LastRun" may be empty (NULL). when i have this it compiles fine but errors out when value is null m_LastRun = Convert.ToDateTime(r["LastRun"]); when I take out Convert.ToDateTime it doesn't even compile.
How can i get the values even when the Source or url is null from the below query
SELECT a.id, isnull((SELECT STUFF((SELECT '<li><a href="'+url+'">'+Source_Name+'</a> <span>(' + k.Source +')</span></li>' end FROM table1 i, table2 k, table3 j where i.CategoryID = j.Category_ID and i.CategoryID = c.Category_ID and i.Source = k.ID FOR XML PATH('')),1, 0, '')), '') AS Source_url, FROM @table4 c INNER JOIN table5 v on c.Category_ID = v.Category_ID
I have a datareader like so but when it encounters a NULL database value, I get the error message "Conversion from type 'DBNull' to type 'String' is not valid."
Dim myReader As SqlDataReader = myCommand.ExecuteReader() Dim yValues As New List(Of Double) With myReader If .HasRows Then While .Read yValues.Add(Double.Parse(.GetValue(0)))........
I have a dropdown list that uses an ObjectDataSource. The select method of the ObjectDataSource needs to localize the TextField, so i create a Dictionary<int, string> and use GetLocalResourceObject as such:
[Code]....
In the Local Resource file, there is status0, status1, and status2, all with a value (Deleted, Active, Inactive). The dropdown and object datasource like:
[Code]....
Now, if I use an ObjectDataSource and put the DropDownList's DataSourceID to it, I will get a null reference on the lookup to the GetLocalResourceObject. BUT If I manually set DataSource/DataBind on the dropdown list on Page_Load, it works fine:
[Code]...
OR If I move the status values to a global resource file and use GetGlobalResource instead of GetLocal, it works fine! Why can I not use an ObjectDataSource and LocalResourceObject in this way?
In following SQL query: SELECT DISTINCT CodeID, CodeDesc FROM Faults.TblFltClearCodes AS TblFltClearCodes
I am getting a list but there is no null value.Within this query I would like to get only one NULL value at the top and then the list.How to do this? Explicitly I am not allowed to give a null value in the table in DB.
iam using asp.net2.0 with c# with sql server 2000 when iam executing the procedure in local system it is working fine.but when iam executing in client system procedure returns null value, i have checked all connection string , and session value all are working
My SQL field 'modified' is a DateTime type and if the value is NULL in SQL I want to display a 'n/a' string. I am using FormView templates to display the value.If I use this statement -> ISNULL(Items.modified,'') AS Modified; I get '1/1/1900 12:00:00 AM' in return.If I use this statement -> ISNULL(Items.modified,'n/a') AS Modified; I get 'Conversion failed when converting datetime from character string.'I could go ahead and change my class from "public DateTime Modified" to "public String Modified" but I want the field to represent its real value which is DateTime.I am not inserting the date value back into the table since the sprocs all take care of that for me. I just want to display the 'n/a' string.So, is there any way to display a SQL DateTime type as a string when its value is NULL inside the table?
what i would like to do is when the value of my sqldatasource is returned, then if it is null, run a code, in my case, redirect them to the login page, heres my code:
string connectionString = ConfigurationManager.ConnectionStrings["PokemonPlanetConnectionStrings"].ConnectionString; string insertSql = "SELECT * FROM LoggedInUsers WHERE UserId = @UserId"; using (SqlConnection myConnection = new SqlConnection(connectionString))
[Code]....
Now what i would simply like to do is, if the select statement searches the database, and the result is not found, the simply redirect them to "register.aspx"
I am creating a TableAdapter using corresponding wizard, with a GetDataByID() query. The select statement is like this:select * from books where ID = ?Thus books are filtered by ID. But in case a null is passed as a parameter, I want to select all records rather than none. Could you please tell me how I can do it?
i want to insert null in smalldatetime column, when user doesn't select any date from the calender control i want to insert null in the databse, i am using typed dataset in my application.
here's my code
[code]....
it gives me the exception "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."
I have pass following SQL Query to the through ObjectDataSource
[Code]....
And I am passing parameter through QueryString and My idea is like when empty string is pass it should show me all records but when I am passing empty string ObjectDataSource is making NULL and I am not getting desire result
I'm developing a website using asp.net 2.0 . I have retrieved a record from database through the query.
SqlConnection con = new SqlConnection(connectionstring); con.Open(); String SQL = "SELECT * FROM Table where attribute1 = value"; SqlCommand cmd = new SqlCommand(SQL, con); SqlDataReader reader = cmd.ExecuteReader();
Sometimes, there is no record matching this query and so null value is retrieved. My question is how to find that the null value is returned. Since If (no record found i.e NULL) certain actions needs to be done and if (records found i.e NOT NULL) ceratin different actions needs to be carried out.
How do I check if my value is empty AND Isnull? I need to check for both, using ISNULL is not enough because the data can change just so that it is empty.
datatype is numeric(4,0) then error is Conversion from string "" to type 'Integer' is not valid. no record is in this textbox and i need to entry null value.so how can i do the same.
Page 1: To add a record in to DB. At this page, as per the user requests , few controls will be added to the page from server side code. one of them is checkbox list. and when user is requesting to save data, its going to the DB. Everything is fine upto now.
Page 2: To edit the record which is entered from page no 1. When user requests to edit the record entered at page no 1, i'm redirecting user to this update page, with record id, and generating the required controls to show the values. Now the main problem is :
When page is loading first time, I m creating the required controls and then assigning the values to them to edit. but after that at each postback, the value of datasource of checkboxlist is becoming null, same case is with the label control. but the value of textbox is same, it is not becoming empty at each postback. In code: In code i have created two method to generate controls.
1st is : to create new controls, and to assign values to them
2nd is : to regenerate the controls at each postback, with the same IDs, but not assigning any value here.
I think viewstate will reload the values of respective controls, if IDs are same.