|
Hey i got it. but that's not compulsory i guess.
|
|
|
|
|
alter procedure mdi_anu
(
@entry_date varchar(20),
@updated_date varchar(20),
@status varchar(20),
@cno varchar(20),
@eno varchar(20)
)
as
begin
declare @SQL varchar(max)
set @SQL='SELECT * FROM anu123 where 1=1 '
--if (@status='ALL')
-- begin
-- set @status='ALL'
-- set @SQL=@SQL + 'and status=''' +@status
--end
if (@status='A')
begin
set @status='A'
--set @SQL=@SQL+' and status='''+@status
end
if (@status='R')
begin
set @status='R'
set @SQL=@SQL+' and status=''' +@status
end
if (@status='D')
begin
set @status='D'
set @SQL=@SQL+' and status=''' +@status
end
if (@status='P')
begin
set @status='P'
set @SQL=@SQL+' and status=''' +@status
end
if (@entry_date<>'' and @updated_date<>'')
begin
set @entry_date =CONVERT (datetime, @entry_date, 103)
set @updated_date= CONVERT(datetime, @updated_date, 103)
set @SQL=@SQL+'and entry_date>=''' +@entry_date+'''and updated_date<='''+@updated_date+''''
end
if (@cno<>'')
begin
set @cno=@cno
set @SQL=@SQL+'and cno=''' +@cno+
end
if (@eno<>'')
begin
set @eno=@eno
set @SQL=@SQL+'and eno=''' +@eno+
end
exec (@SQL)
end
the error which m getting is that,suppose m choosing 'D' as my input in the status i get
"Unclosed quotation mark after the character string 'D'.
Incorrect syntax near 'D'."
Whats the problem?
|
|
|
|
|
May be you should append a single quotes after +@status in all your if conditions, if it a varchar field?
|
|
|
|
|
Include a space before and after every string. For example instead of writing 'and eno=''' write ' and eno='' '
Hope it helps. If it does not instead of exec(@SQL) in your SP write print(@SQL) and you will have the complete SQL Query. That will clear the picture to a good deal where the error is.
|
|
|
|
|
Hi,
I have a members website and every memeber will have his images saved ina folder on host.
I wanted to ask what's best way to do it:
/member_id/images
or
/member_guid/images
Technology News @ www.JassimRahma.com
|
|
|
|
|
Jassim Rahma wrote: /member_id/images
I would go with Member_Id as that sounds unique and will have a significant value.
|
|
|
|
|
Hi,
if the id will be changed, I suggest to choose the first one, or they are the same.
Comm100 - Leading Live Chat Software Provider
modified 28-May-14 1:46am.
|
|
|
|
|
Hi,
I have been using ExecuteNonReader for a quite long time now and it's doing great for me. For example
SqlCommand cmd = new SqlCommand("select count(uname) from users_tbl where uname=@uname and password=@password", con);
cmd.Parameters.AddWithValue("uname", username);
cmd.Parameters.AddWithValue("password", password);
con.Open();
cmd.ExecuteNonReader();
then why should I use it like this:
SqlCommand cmd = new SqlCommand("select count(uname) from users_tbl where uname=@uname and password=@password", con);
cmd.Parameters.AddWithValue("uname", username);
cmd.Parameters.AddWithValue("password", password);
con.Open();
cmd.ExecuteScalar();
Technology News @ www.JassimRahma.com
|
|
|
|
|
Jassim Rahma wrote: ExecuteNonReader
I don't find a knowledge base article for the same in MSDN. Based on what I know and can infer, using it to get just a 'single' value will be an overhead. It should be used when database query is going to provide a set of records.
My guess, term in discussion is ExecuteNonQuery and should not be ExecuteNonReader .
Jassim Rahma wrote: ExecuteScalar
Executes the query, and returns the first column of the first row in the result set returned by the query.
Refer: Refer: SqlCommand.ExecuteScalar Method [^]
Now, based on the details and documentation, for getting a count, ExecuteScalar fits in the best that will get me the result directly as needed.
|
|
|
|
|
Hi,
ExecuteNonReader: used actions like insert, update, delete
ExecuteScalar: will return an object
for details you can learn from some books about these two.
Thanks,
CommDev
modified 6-Dec-16 1:27am.
|
|
|
|
|
Hi,
ExecuteReader
Do not use: when database query is going to provide for sure exactly 1 record. It may be getting record by its id (which is PK in the database) - GetOrderById and such. In this case use ExecuteNonQuery with output parameters.
Use: when database query is going to provide a set of records. It may be search or report.
ExecuteNonQuery
Use: when we are talking about a single database record - in Update, Insert, Delete and Get by Id. In all these cases we can use input/output/input-output parameters. Please note that from the application architecture point of view it is also good practices when your Insert and Update stored procedure returns changed record exactly like Get By Id method does.
ExecuteScalar
Do not use: when database query returns a single value and this value can be defined as parameter in T-SQL. ExecuteNonQuery with output parameter(s) is always preferred in this case since it is more flexible, tomorrow there will be 2 values therefore having ExecuteNonQuery we do not need to change method signatures.
Use: when database query returns a single value and this value cannot be defined as output parameter, because of T-SQL type limitation for variables. For example type image cannot be output parameter in MSSQL.
The most common example for ExecuteScalar is fetching a single image stored in the database and converting it to array of bytes. If you google it - most examples will demonstrate using of ExecuteReader to accomplish image handler, however ExecuteScalar will be more scalable and faster.
Conclusion
Always use ExecuteNonQuery except: when you have a set of records - use ExecuteReader and when you have a single output value that cannot be defined as a parameter - use ExecuteScalar. Hope this helped to clarify something. Enjoy
Comm100 - Leading Live Chat Software Provider
|
|
|
|
|
Thanks CommDev.
But if I am going to return GetOrderById.. what's the difference if I am going to use ExecuteNonQuery with Output parameter or ExecuteReader with return SqldataReader?
Does it make a difference specially performance wise?
Technology News @ www.JassimRahma.com
|
|
|
|
|
hi,
Generally we use execute scalar function for displaying the first column and first row, but if we use ExecuteNonReader it will show error why because in asp.net only 3 commands are there ExecuteReader()
ExecuteNonQuery()
ExecuteScalar() this is the option to get one value from the database.
|
|
|
|
|
Guys;
I am developing a control that should contain html elements
like
<web:CommandLink ID="cmdDelete" runat="Server" >
<img alt="Delete" src="images/delete.jpg" />
</web:CommandLink>
I started with implementing IParserAccessor .
Am I in the right direction ?
Thank you.
Help people,so poeple can help you.
modified 24-Dec-12 5:29am.
|
|
|
|
|
So your trying to make a server or user control?
|
|
|
|
|
A server one.
the new thing is I implemented IParserAccessor.AddParsedSubObject this way
Public Sub AddParsedSubObject(ByVal obj As Object) Implements System.Web.UI.IParserAccessor.AddParsedSubObject
If (TypeOf (obj) Is LiteralControl) Then
Me._templateText = CType(obj, LiteralControl).Text
Else
Throw New Exception("Not supported")
End If
End Sub
it works fine but it gives me the validation error 'img cannot be nested with commandlink'.
what should I do to avoid that?
Help people,so poeple can help you.
|
|
|
|
|
Hi All
i have a gridview
<asp:GridView ID="GridView2" runat="server" Width="100%"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="description" HeaderText="Description" >
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="Amount" HeaderText="Amount" >
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:TemplateField HeaderText="Month">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxJan" runat="server" Text="Jan" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
<asp:CheckBox ID="CheckBoxFeb" runat="server" Text="Feb" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
<asp:CheckBox ID="CheckBoxMar" runat="server" Text="Mar" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
<asp:CheckBox ID="CheckBoxApr" runat="server" Text="Apr" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
<asp:CheckBox ID="CheckBoxMay" runat="server" Text="May" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
<asp:CheckBox ID="CheckBoxJun" runat="server" Text="Jun" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
<asp:CheckBox ID="CheckBoxJul" runat="server" Text="Jul" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
<asp:CheckBox ID="CheckBoxAug" runat="server" Text="Aug" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
<asp:CheckBox ID="CheckBoxSep" runat="server" Text="Sep" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
<asp:CheckBox ID="CheckBoxOct" runat="server" Text="Oct" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
<asp:CheckBox ID="CheckBoxNov" runat="server" Text="Nov" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
<asp:CheckBox ID="CheckBoxDec" runat="server" Text="Dec" AutoPostBack="True"
oncheckedchanged="CheckBoxJan_CheckedChanged" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
</Columns>
</asp:GridView>
and i am using checked change event for checkbox as
protected void CheckBoxJan_CheckedChanged(object sender, EventArgs e)
{
string desc = "";
Double amount = 0;
for (Int32 i = 0; i < GridView2.Rows.Count; i++)
{
double amt = 0;
CheckBox checkBox1 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxJan");
bool isChecked1 = checkBox1.Checked;
CheckBox checkBox2 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxFeb");
bool isChecked2 = checkBox2.Checked;
CheckBox checkBox3 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxMar");
bool isChecked3 = checkBox3.Checked;
CheckBox checkBox4 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxApr");
bool isChecked4 = checkBox4.Checked;
CheckBox checkBox5 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxMay");
bool isChecked5 = checkBox5.Checked;
CheckBox checkBox6 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxJun");
bool isChecked6 = checkBox6.Checked;
CheckBox checkBox7 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxJul");
bool isChecked7 = checkBox7.Checked;
CheckBox checkBox8 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxAug");
CheckBox checkBox9 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxSep");
bool isChecked8 = checkBox8.Checked;
CheckBox checkBox10 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxOct");
bool isChecked9 = checkBox9.Checked;
CheckBox checkBox11 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxNov");
CheckBox checkBox12 = (CheckBox)GridView2.Rows[i].Cells[2].FindControl("CheckBoxDec");
bool isChecked10 = checkBox10.Checked;
bool isChecked11 = checkBox11.Checked;
bool isChecked12 = checkBox12.Checked;
if (isChecked1 && checkBox1.Enabled==true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "Jan" + ",";
}
if (isChecked2 && checkBox2.Enabled == true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "Feb" + ",";
}
if (isChecked3 && checkBox3.Enabled == true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "Mar" + ",";
}
if (isChecked4 && checkBox4.Enabled == true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "Apr" + ",";
}
if (isChecked5 && checkBox5.Enabled == true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "May" + ",";
}
if (isChecked6 && checkBox6.Enabled == true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "Jun" + ",";
}
if (isChecked7 && checkBox7.Enabled == true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "Jul" + ",";
}
if (isChecked8 && checkBox8.Enabled == true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "Aug" + ",";
}
if (isChecked9 && checkBox9.Enabled == true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "Sep" + ",";
}
if (isChecked10 && checkBox10.Enabled == true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "Oct" + ",";
}
if (isChecked11 && checkBox11.Enabled == true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "Nov" + ",";
}
if (isChecked12 && checkBox12.Enabled == true)
{
amt = Convert.ToDouble(GridView2.Rows[i].Cells[1].Text);
amount = amount + amt;
desc = desc + "Dec" + ",";
}
}
Label24.Text = amount.ToString();
Label17.Text = (Convert.ToDouble(Label23.Text) + Convert.ToDouble(Label24.Text) + Convert.ToDouble(Label27.Text)).ToString();
Label29.Text = desc;
}
so here after every checked change page is getting reloaded but i want to do this in javascript(client side)
so please help me to do this
regards
Ravi kant
|
|
|
|
|
|
|
helo frnds,
im trying to capture updated data from gridview upon check box selection..
however im unable to retreive new data..
it alwasy capture old data...pls help me...
i haave used gridediteventargs..but in vain......
i want to capture new data in button click event
best rgrds
nancy
|
|
|
|
|
Ma'am;
You have a gridview with a check box in each row and you want an array of the selected rows keys. right?
if so, you should have a template column that contain a check box with a specific name say 'Selection'
<input type="checkbox" name="Selection" value="<%# Eval("Key")%>" />
when you postback the page you can get the array using Request["Selection"]
Help people,so poeple can help you.
|
|
|
|
|
Member 9707207 wrote: im trying to capture updated data from gridview upon check box selection..however im unable to retreive new data..
Just check if you are binding the grid data again on postback. If so, before the update event is raised the data will be back to previous state and changes will be lost.
You need to put the databind code for the grid in Page.IsPostback property to avoid a rebind until unless specified in a postback.
|
|
|
|
|
How to convert English words to Hindi words with help of coding it is possible with out any data base?
|
|
|
|
|
Think about this: how many words do you expect to convert? Can you keep that many words somewhere without a database of some sort?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi,
You can try Google Translator API. Given link may be useful to you.
Google Translator[^]
Maulik Dusara
Sr. Sofware Engineer
|
|
|
|