|
Could you post a bit of your code? This may help maybe...
Regards
Sebastian
|
|
|
|
|
Try
'select from table where field is LIKE '%" + name.Replace("'", "''") + "%'"
For a better, and safer, solution look into using parameters in your SQL.
|
|
|
|
|
Ive replaced the apostrophies and it doesnt show an error message but now it just wont find that field which is weird. The sql statement is searching a table for fields that match the description the user puts in.
Is this because the apostrophies are not recognised in the field?
thanks
OK forget what I said above.
I think the problem is that there are breaks in the text in the database field, i.e. a new line so this might be causing the error of not finding it.
Is this a known problem when searching database fields that if there is a line break in the field it affects finding data?
thanks
modified on Monday, June 29, 2009 8:26 AM
|
|
|
|
|
Oh I see, the value of name can contain ''...
DoctorMick already gave the answer. But just one advice: Pay attention to sql injection (http://unixwiz.net/techtips/sql-injection.html[^]). You could use preparedstatements within your code. This will be the better (and more secure) way.
Regards
Sebastian
|
|
|
|
|
Try this
select from table where field is LIKE RTRIM(LTRIM('%" + name + "%'))"
Hope this helps
Niladri Biswas
|
|
|
|
|
Hi...
I want to send mail through attachment class.
I want to pass stream data into it,from database with datatype image.
Here is the code....
protected void btnSendMail_OnClick(object sender, ImageClickEventArgs e)
{
MailAddress from = new MailAddress(Config.MailFrom);
MailAddress to = new MailAddress(lblToMail.Text);
MailMessage mail = new MailMessage(from, to);
mail.Subject = lblSubject.Text;
mail.Body = txtMailBody.Text;
mail.IsBodyHtml = true;
mail.Sender = from;
string strCommand = "select ID,FileName,Extension,Iszip,Content1,Image_Type,ByloginCode,OnDate from ZipFile where ID=" + iAttachmentFileCode + " ";
DataTable dt = new DataTable();
if (objDbTrans.ExecuteDataAdapter(strCommand, ref dt))
{
foreach (DataRow row1 in dt.Rows)
{
byte[] reportFile = (byte[])row1["Content1"];
string strfileName = row1["FileName"].ToString();
MemoryStream stmContent;
stmContent = new MemoryStream(reportFile);
Attachment attachFile = new Attachment(stmContent,strfileName);
mail.Attachments.Add(attachFile);
}
}
SmtpClient SmtpMail = new SmtpClient(Config.MailServerSmtp);
SmtpMail.Send(mail);
}
mail is sent with file name,nut its content is blank.
Here Content1 is the datatable field with datatype image, containg binary data.
Plz,help to solve this issue.
Thanks.
Regardds,
PUJA FALDU
|
|
|
|
|
pujafaldu wrote: MemoryStream stmContent;
stmContent = new MemoryStream(reportFile);
using(MemoryStream memStream = new MemoryStream(firstString.Length))
{
memStream.Write(reportFile, 0 , reportFile.Length);
Attachment attachFile = new Attachment(stmContent,strfileName);
mail.Attachments.Add(attachFile);
}
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi...
i have made changes according to you.but it not works...
here is the changed code.
byte[] reportFile = (byte[])row1["Content1"];
string strfileName = row1["FileName"].ToString();
MemoryStream stmContent;
stmContent = new MemoryStream(reportFile);
using (MemoryStream memStream = new MemoryStream(reportFile.Length))
{
// Write the first string to the stream.
memStream.Write(reportFile, 0, reportFile.Length);
Attachment attachFile = new Attachment(stmContent, strfileName);
mail.Attachments.Add(attachFile);
}
|
|
|
|
|
This is incorrect. You should not dispose stream before sending the mail.
|
|
|
|
|
Are you getting data correctly into the byte array? You are using this[^] constructor of attachment class where the second parameter is name of the content type not the file name. You need to specify a content type which says the data is image.
|
|
|
|
|
I am using this code to generate Treeview dynamically from the database.....output is coming but...not as desired.....means Category's connected field are coming to Sub-Category1 and Sub-Category1's field are showing in Sub-Category2..........plz chk and let me know whether the loop is rite or not? code is:
Dim ParentNode As String(,) = New String(100, 2) {}
Dim count As Integer = 0
Dim db As Database = DatabaseFactory.CreateDatabase("See2Buy")
Dim cmd As String = "Select CategoryID, CategoryName From Cat ORDER BY CategoryID"
Dim rdr As IDataReader = db.ExecuteReader(CommandType.Text, cmd)
While rdr.Read()
ParentNode(count, 0) = rdr.GetValue(rdr.GetOrdinal("CategoryID")).ToString()
ParentNode(System.Math.Max(System.Threading.Interlocked.Increment(count), count - 1), 1) = rdr.GetValue(rdr.GetOrdinal("CategoryName")).ToString()
End While
'rdr.Close()
For [loop] As Integer = 0 To count - 1
Dim root As New TreeNode()
root.Text = ParentNode([loop], 1)
'root.Target = "_blank"
root.Value = ParentNode([loop], 1)
root.NavigateUrl = "SubCat1.aspx?id=" + root.Value
Dim cmd1 As String = " Select SubCat1ID, SubCategoryName from SubCat1 where CategoryID =" & ParentNode([loop], 0)
'Dim Module_Sdr As SqlDataReader = Module_SqlCmd.ExecuteReader()
Dim rdr1 As IDataReader = db.ExecuteReader(CommandType.Text, cmd1)
While rdr1.Read()
Dim child As New TreeNode()
child.Text = rdr1.GetValue(rdr1.GetOrdinal("SubCategoryName")).ToString()
root.ChildNodes.Add(child)
Dim cmd2 As String = " Select SubCat2ID, SubCategoryName from SubCat2 where CategoryID =" & ParentNode([loop], 0)
Dim rdr2 As IDataReader = db.ExecuteReader(CommandType.Text, cmd2)
While rdr2.Read
Dim child2 As New TreeNode()
child2.Text = rdr2.GetValue(rdr2.GetOrdinal("SubCategoryName")).ToString()
child2.Target = "_blank"
child2.NavigateUrl = "Default.aspx"
child.ChildNodes.Add(child2)
End While
End While
rdr1.Close()
TreeView1.Nodes.Add(root)
TreeView1.CollapseAll()
Next
|
|
|
|
|
Your whole design is broken. You should just set the parent id of each child, not have a seperate table for each level. Beyond that, you should step through your code to try to work out what is wrong.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
I have been noticing that you have been trying to do this for almost a week now.
Every time you come up to the CP for the next step.
In between, do you mind to put your code in PRE tag from next time it makes lives simple to read and understand the code.
As far as your code is concerned, I do not understand why did you make it this complex. I gave you SQL query hint [^]to get all the categories and sub categories from database.
Did you try that approach? I am sure it would have simply solved your problem of you would have gone step by step for you goal
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Thanks for ur Code Mr. Manas that u gave me last time.....but that was showing just a single Category and single Sub-Category......thats why i did this one.........I am a new guy thats why comes to CP
|
|
|
|
|
As I understood, you need to create a tree of categories where each category may be a child and/or a parent to another .. if so,
- You need 2 columns in the Categories table, (CategoryId, ParetntId)
both must be of the same data type
- Then you have to set the CategoryId as PK, and ParentId as FK from the table itself
- Now we have finished the server side work.
- on the client side, you may load the table into a dataset object (name it CategoriesDataSet )
- To display the data on the tree control, no need for loops
- Just set the following properties to the tree control
DataSource = CategoriesDataSet<br />
ParentId = ParentId<br />
FieldId = CategoryId
Finally call DataBind()
foreach(Minute m in MyLife)
myExperience++;
|
|
|
|
|
Hi Guys
In ASP.Net 2.0 application i am using ajax(toolkit Script manager)
In My Application there are two panel, On Page load one panel visible is true After Click On A button, first Panel Visible= False and second panel visible = true
on second panel there is a start button
After Click On that Button i am getting this Error
while In IE 6.0 this application working perfectally
Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0
What will be solution for that
Please Help Me
Thanks In Advanced
krishna veer singh
|
|
|
|
|
|
I Implemented it
but its not working
so any other solution, SIR
krishna veer singh
|
|
|
|
|
Hi,
I am a beginner in .Net.
In my application i have 4 panels.
But,during postback(such as a button click event),the focus automatically goes to the first panel.
In web,i found on idea to use TabbedPanels1.showPanel(tabindex) on button's onclick event.
But,both in the OnClientClick and OnServerClick events i have written the validation and some task to be done respectively.
How to persist the focus on the panel during postback?
Thanks in advance
Yazhini
|
|
|
|
|
YazhiniP wrote: But,both in the OnClientClick and OnServerClick events i have written the validation and some task to be done respectively.
You should always do validation on the server side, don't trust the client validation.
If there's no server side focus method to call, then you need to write javascript to do it.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Hi all ,
How i deal with the File Uplad control in View control . i placed the Fileuplaod control on view control .
Is Fileupload stored data in viewstate like others controls inside view control ?
Any Idea or link ?
Best Regards
|
|
|
|
|
Rameez Raja wrote: Is Fileupload stored data in viewstate like others controls inside view control ?
No. It's a html file input control, it's data is sent to the server, but it's not stored in viewstate.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Thanks for reply ,
It is server side control not the html file input control if not then kindly suggest me how i deal with fileupload control issue in view control ?
Best Regards
|
|
|
|
|
Rameez Raja wrote: It is server side control not the html file input control
There is no such thing as a server side control, on the client. The 'server side control' is rendered as a html control, that's all it could ever be. whatever happens, on postback, your control will contain the bytes of your file and it's name. viewstate is for persisting values between postbacks, a file is assigned, sent on that postback and forgotten.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Christian Graus wrote: There is no such thing as a server side control, on the client. The 'server side control' is rendered as a html control, that's all it could ever be. whatever happens, on postback, your control will contain the bytes of your file and it's name. viewstate is for persisting values between postbacks, a file is assigned, sent on that postback and forgotten.
Thanks for reply,
Ok iam agreed with you now how i deal with uplaoding the image may i have to store in folder Temprarly and called during displaying summary am i right ?
Suggest me good option to deal with uploading .
Best Regards
|
|
|
|