Simply Search Engine

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2009
Posts: 88
Reputation: IdanS is an unknown quantity at this point 
Solved Threads: 12
IdanS IdanS is offline Offline
Junior Poster in Training

Re: Simply Search Engine

 
0
  #11
Jun 29th, 2009
serkan sendur offcourse it vulnerable to sql injection,
but i dont know if you noticed above is a beginner to c#,
and as it seems he is a beginner in programing as well, so we are not dealing with vulnerabilty here, he simply wants to start to learn.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 12
Reputation: dummy C# is an unknown quantity at this point 
Solved Threads: 0
dummy C# dummy C# is offline Offline
Newbie Poster

Re: Simply Search Engine

 
-1
  #12
Jun 29th, 2009
i want show my result of search in a datagridview. i just want selected title o date i key in show there.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace WindowsFormsApplication7
{
public partial class Form7 : Form
{
public Form7()
{
InitializeComponent();
}

private void BindDataGrid()
{
SqlConnection myConn = new SqlConnection();
myConn.ConnectionString = ConfigurationManager.ConnectionStrings["myConn"].ToString();

myConn.Open();


string strSQL = "select * from book where user_id = " + StaticData.ActiveUserId + "";
SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, myConn);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

SqlCommand cmd = new SqlCommand("select user_id from book where user_id = " + StaticData.ActiveUserId + "", myConn);

DataTable table = new DataTable();
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
dataGridView1.DataSource = bindingSource1;

myConn.Close();
}



private void button1_Click(object sender, EventArgs e)
{

SqlConnection myConn = new SqlConnection();
myConn.ConnectionString = ConfigurationManager.ConnectionStrings["myConn"].ToString();

myConn.Open();

if (txtTitle.Text != "")
{

SqlCommand cmd = new SqlCommand("SELECT * from book WHERE title = " + txtTitle.Text.ToString());

SqlDataReader dr;
dr = cmd.ExecuteReader();

BindDataGrid();

dr.Close();
}
else if (txtDate.Text != "")
{
SqlCommand cmd = new SqlCommand("SELECT * from book WHERE dateofpurchase = " + txtDate.Text.ToString());

SqlDataReader dr;
dr = cmd.ExecuteReader();

dr.Close();
}


myConn.Close();




}
}
}
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 122
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Simply Search Engine

 
0
  #13
Jun 29th, 2009
you should add the parameters like below :

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Data.SqlTypes;
  7.  
  8. public class MainClass
  9. {
  10. [STAThread]
  11. static void Main()
  12. {
  13. string cstr = "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;";
  14. using ( SqlConnection conn = new SqlConnection( cstr ) )
  15. {
  16. conn.Open();
  17.  
  18. string selstr = "select FirstName from Employee where lastname = @name";
  19. SqlCommand cmd = new SqlCommand( selstr, conn );
  20. SqlParameter name = cmd.Parameters.Add( "@name", SqlDbType.NVarChar, 15 );
  21. name.Value = "Tang";
  22. SqlDataReader rdr = cmd.ExecuteReader();
  23.  
  24. if ( rdr.Read() )
  25. {
  26. Console.WriteLine(rdr.GetString( 0 ) );
  27. }
  28. else
  29. {
  30. Console.WriteLine("not available yet" );
  31. }
  32. }
  33.  
  34. }
  35. }

"Tang" will be your textbox.text.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 122
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Simply Search Engine

 
0
  #14
Jun 29th, 2009
Originally Posted by IdanS View Post
serkan sendur offcourse it vulnerable to sql injection,
but i dont know if you noticed above is a beginner to c#,
and as it seems he is a beginner in programing as well, so we are not dealing with vulnerabilty here, he simply wants to start to learn.
i posted an example as how to create parameters in secure way. this way it will be protected against injection.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 88
Reputation: IdanS is an unknown quantity at this point 
Solved Threads: 12
IdanS IdanS is offline Offline
Junior Poster in Training

Re: Simply Search Engine

 
0
  #15
Jun 29th, 2009
dummy c# you are now using two different methods of polling the data from the DB, either you want to use DataBind or you want to use SqlDataReader, choose one and we will continue from there.

and you have not still added the:
  1. dr.Read()
Method
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 88
Reputation: IdanS is an unknown quantity at this point 
Solved Threads: 12
IdanS IdanS is offline Offline
Junior Poster in Training

Re: Simply Search Engine

 
0
  #16
Jun 29th, 2009
Originally Posted by serkan sendur View Post
i posted an example as how to create parameters in secure way. this way it will be protected against injection.
WOW you are so centered in your self that you quote me and tell me sonthing else, I KNOW HOW TO DO IT IN A SECURE WAY, BUT ITS NOT THE ISSUE...!!!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 122
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Simply Search Engine

 
0
  #17
Jun 29th, 2009
what were you expecting ? am i going to be "you" centered, of course i am self-centered.
if you teach someone something, why not teach it correct from the beginning?
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 88
Reputation: IdanS is an unknown quantity at this point 
Solved Threads: 12
IdanS IdanS is offline Offline
Junior Poster in Training

Re: Simply Search Engine

 
1
  #18
Jun 29th, 2009
Becuase when you teach a baby to talk you are not teaching him how to say "encyclopedia" from the begining you teaching him how to say "dad", "mom" and so on, when he learned that so you going and teach him how to say "cow", "cat" and after you teach him to say "encyclopedia".

I'm sure when you started to learn programing you didnt learn how to id in a secure way from the begining you learned the basicics and then you developed to what you know today, so take it easy with the fellow
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 122
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Simply Search Engine

 
0
  #19
Jun 29th, 2009
I dont think so, even in the microsoft websites beginning tutorials for novices, it teaches how to do it proper way from the beginning. Using one more object is better than making quotation mistakes in a select statement as well as security issue.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 88
Reputation: IdanS is an unknown quantity at this point 
Solved Threads: 12
IdanS IdanS is offline Offline
Junior Poster in Training

Re: Simply Search Engine

 
-1
  #20
Jun 29th, 2009
Well obviously you are not a perent and not a teacher either.
If you still think that you are right so stay in your mind, I cant force you to change the way you think, but I'm sure that people here will agree with me.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC