|
|
Hi,
Question, I was trying to get expiry date from my database, I already got those list display on my Listview.
But when Im trying to update the year. Still showing on my list.
sample Date today is 13-Apr-2019, i want to display those upcoming expiry +30 Days.
but if I update it to 13-Apr-2020, still showing.
My code i use.
"Select * from TblEmployee where IDExpiry<=@IDExpiry"
siemdi.Parameters.Add("@IDExpiry", OleDbType.Date).Value = DateTime.Today.AddDays(30)
|
|
|
|
|
Your question is not much clear but your query will return you data for whatever date you pass as parameter and if Tblemployee has the data. if you just want to get expiry data for next 30 days you should have logic not to pass future date.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
That doesn't make much sense to me. If the expiry date is on or before today, then it's also on or before 30 days in the future. Or a year in the future.
What are you actually trying to return?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You should return a model when you read the database.
A model is a strong typed class that you use to store data in.
Once you have the model populated, you can add 30 days to the date column by using .AddDays(30) in a loop.
So matter what month it is, it will calculate the proper date.
Eg Model:
public class Example {
public string Name { get; set; }
public DateTime Expires { get; set; }
}
Request data and populate the model
var examples = getExamples();
for each example in examples {
example.Expires.AddDays(30);
}
If your not using models, then you be able to figure this out somehow. You just need a DateTime Object and AddDays(30)
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Hi Friends,
Can anyone help me with this?
Using 3 tier architecture,how to fetch data directly from database table to textboxes when I clicked on select button in grid view,I have a table in SQL database.Upon clicking on select link button in grid view,the selected row values must be fetched from database table to text boxes and must be filled with respective values according to database table.I have used sqldatareader, taken OnSelectedIndexChanged ,written query in stored procedure for fetching selected row but values are not binding to text boxes.Any suggestions would be helpful.
|
|
|
|
|
As you did not showed what you have tried it will be hard us to know. Did you tried to debug and see if you really pulling any values back on your event to bind?
modified 20-Sep-20 21:01pm.
|
|
|
|
|
DAL:
public DataTable FetchDetails(string pid, string pname, string pcid, string sdesc, string desc, string qty, string prce, string len)
{
var a = new ArrayList();
SqlCommand cmd = new SqlCommand("spfetchdetail", con);
con.Open();
cmd.ExecuteNonQuery();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pid", pid);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
pid = sdr["P_id"].ToString();
pname = sdr["P_name"].ToString();
pcid = sdr["c_name"].ToString();
sdesc = sdr["P_shortdesc"].ToString();
desc = sdr["P_desc"].ToString();
qty = sdr["P_qty"].ToString();
prce = sdr["P_price"].ToString();
len = sdr["P_length"].ToString();
a.Add(pid); a.Add(pname); a.Add(pcid); a.Add(sdesc); a.Add(desc); a.Add(qty); a.Add(prce); a.Add(len);
}
return dt;
}
BAL:
public object fetchdetail(string pid, string pname, string pcid, string sdesc, string desc, string qty, string prce, string len)
{
return dll.FetchDetails(pid, pname, pcid, sdesc, desc, qty, prce, len);
}
CS:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string pid = ""; string pname = ""; string pcid = ""; string sdesc = ""; string desc = ""; string qty = ""; string prce = ""; string len = "";
bll.fetchdetail(pid, pname, pcid, sdesc, desc, qty, prce, len);
HiddenField1.Value = pid;
txt_proName.Text = pname;
ddl_category.SelectedValue = pcid;
txt_sdesc.Text = sdesc;
txt_ldesc.Text = desc;
txt_qnty.Text = qty;
txt_price.Text = prce;
txt_len.Text = len;
}
|
|
|
|
|
Couple of issues with your code in
FetchDetails method.
1. You have populated the result into arraylist object which is local to this function
2. You executing command object with ExecuteNonQuery, Reader and DataAdapter
3. You populated Dataset to return from FetchDetails in DAL and did not received it in calling method to bind data.
Populate your local variables in SelectChange event from DataSet object you reveiced from BAL and should work for you.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Thank u for u r response.
Unfortunately I am new to work with three tier, I am unable to get your point.Could u pls modify the code which i have provided so that it will be very helpful for me.
|
|
|
|
|
Here you go. You need to extract data from data table now in below code to populate your variables which you may be binding on screen.
DAL:
public DataTable FetchDetails()
{
con.Open();
DataTable dt = new DataTable();
using(SqlCommand cmd = new SqlCommand("spfetchdetail", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pid", pid);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
}
return dt.Table[0];
}
BAL:
public DataTable fetchdetail()
{
return dll.FetchDetails();
}
CS:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string pid = ""; string pname = ""; string pcid = ""; string sdesc = ""; string desc = ""; string qty = ""; string prce = ""; string len = "";
DataTable dt = bll.fetchdetail();
HiddenField1.Value = pid;
txt_proName.Text = pname;
ddl_category.SelectedValue = pcid;
txt_sdesc.Text = sdesc;
txt_ldesc.Text = desc;
txt_qnty.Text = qty;
txt_price.Text = prce;
txt_len.Text = len;
}
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Thank u soo much for your reply.
But unfortunately i'm getting error in DAL
The name 'pid' does not exist in the current context
This is my Stored Procedure:
CREATE proc [dbo].[spfetchdetail]
<a href="https://www.codeproject.com/Members/pid">@pid</a> int
as
begin
select * from Products LEFT JOIN Category ON Products.P_C_id=Category.c_id where P_id=@pid
end
-- modified 16-Apr-19 10:04am.
|
|
|
|
|
I might have removed all params so its error. You should pass the pid as parameter to DAL to resolve it.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
In DAL
public DataTable FetchDetails(int pid)
{
con.Open();
DataTable dt = new DataTable();
using (SqlCommand cmd = new SqlCommand("spfetchdetail", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pid", pid);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
}
return dt;
}
In BAL:
public DataTable fetchdetail(int pid)
{
return dll.FetchDetails(pid);
}
In CS page,passing pid
string pid="";string pname = ""; string sdesc = ""; string desc = "";
string qty = ""; string prce = ""; string len = "";
DataTable dt = bll.fetchdetail(pid);
getting type conversion error
|
|
|
|
|
Well gave you direction but cant fix all here as it wont run. You need to debug and identify the issue. check if you really have data coming from SP outout in debug
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Thank u so much vinod, i have modified the code a little and its perfectly working now.Thank u for ur time.
|
|
|
|
|
Hi,
I want when I enters information in the field, then the title of the field goes over the field.
Herre is my code:
@Html.TextBoxFor(model => model.FirstName, new { @placeholder = "FIRSTNAME", @class = "adresse-input"})
so in the field we have the text "FIRSTNAME", my purpose is when i enters information in this field, the text "FIRSTNAME" goes over the field.
And as long as the client has nothing to enter in a field, then the title remains in the field.
I search a lot if there is a trick to add in TextBoxFor to do that but i didn't find!
Thanks a lot
|
|
|
|
|
Have you looked into CSS for your class for placeholder? Below is something similar you are looking for -
Placeholder for textbox[^]
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Are you looking for something like this?
Float Labels with CSS | CSS-Tricks[^]
If not, then you'll need to explain what you mean by "goes over the field".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello,
I would like to show error when is some of radion buttons is not checked. This is the code:
<pre><div class="floatLeft ml_15">
<asp:Literal ID="litPatientTypeO9" runat="server"></asp:Literal> *
<br />
<asp:RadioButton ID="rbtnNewO9" runat="server" GroupName="PatientTypeO9" CssClass="checkBox" />
<br />
<asp:RadioButton ID="rbtnRecidedO9" runat="server" GroupName="PatientTypeO9" CssClass="checkBox" />
<br />
<asp:RadioButton ID="rbtnUnsucessfulyTreatedO9" runat="server" GroupName="PatientTypeO9" CssClass="checkBox" />
<br />
<asp:RadioButton ID="rbtnTreatedAfterBrakeO9" runat="server" GroupName="PatientTypeO9" CssClass="checkBox" />
<br />
<asp:RadioButton ID="rbtnMovedO9" runat="server" GroupName="PatientTypeO9" CssClass="checkBox" />
<br />
<div id="divOtherType09" runat="server" class="floatLeft" style="padding-top: 3px;">
<asp:RadioButton ID="rbtnOtherTypeO9" runat="server"
GroupName="PatientTypeO9" OnCheckedChanged="rbtnrbtnOtherTypeO9_CheckedChanged" AutoPostBack="true" CssClass="checkBox" />
</div>
<div class="floatLeft">
<uc1:TextBoxControl ID="txtOtherTypeO9" runat="server" />
</div>
</div>
So, all of this radio buttons are not checked and if they stay empty I like to show error message to user so must choose one.
Thank you
|
|
|
|
|
|
Hello
After adding MSSQLLocalDB and ProjectsV13 servers to my Web project which is based on the Register.aspx and Logon.aspx files in Microsoft's WebFormsIdentity template, I have the following in my Web.config file:
<pre><?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"/>
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebFormsIdentity-20190319020136.mdf;Initial Catalog=aspnet-WebFormsIdentity-20190319020136;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<authentication mode="None"/>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.6.1"/>
<httpRuntime targetFramework="4.6.1"/>
<pages>
<namespaces>
<add namespace="System.Web.Optimization"/>
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
<membership>
<providers>
<!--
ASP.NET Membership is disabled in this template. Please visit the following link https://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
-->
<clear/>
</providers>
</membership>
<profile>
<providers>
<!--
ASP.NET Membership Profile is disabled in this template. Please visit the following link https://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
-->
<clear/>
</providers>
</profile>
<roleManager>
<!--
ASP.NET Membership Role is disabled in this template. Please visit the following link https://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
-->
<providers>
<clear/>
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider"
type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="DefaultConnection"/>
</providers>
</sessionState>
</system.web>
etc
I am interested in enabling ASP.NET Membership, ASP.NET Membership Profile, and ASP.NET Membership Role. I have visited the link provided by Microsoft but it doesn't tell me much and seems outdated. For ASP.NET Membership, I am proposing:
<membership>
<providers>
<clear />
<add
name="Net SqlClient Data Provider"
type="System.Web.Security.SqlMembershipProvider" 'not sure of the type for my own project: where do I find that information?
connectionStringName="MySqlConnection" 'MSSQL.LocalDB?
applicationName="WebFormsIdentity"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
passwordFormat="Hashed" />
</providers>
</membership>
but have no idea about how to enable Membership Profile or ASP.NET Membership Role.
Thank you for any advice.
|
|
|
|
|
|
No. Because most people don't download random zip files.
If you want us to look at code (and I'm assuming you do) copy'n'paste it into your question, enclosed in pre tags:
<pre lang="cs">if ( x == y)
i = 6;</pre> Will give you:
if (x == y)
i = 6; You can add the tags via the "code" widget above the edit textbox.
And tell us where the error occurs, and copy the error message.
Just throwing a zip up on a dodgy download site and expecting us to download it, examine the content and work out where the problem might be is a bad idea ...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Have you looked at my example ?
|
|
|
|