You´re right, at the moment I´m taking my first trembling steps in programming, and it´s probably a good Idea to learn from the start to think about security. Thanks
erikhjerpe
Posts
-
Need help with Sqldatareader -
Need help with SqldatareaderThank you very much for the tips, I certainly will look into DataAdapters, have a vague ideea that thats what I´m looking for. About Injection attacks Im´not afraid since the application is supposed for a closed network and without any input from users other than to load a form. (Trying to build a system of info displays). Anyway thanks a lot for your answers
-
Need help with SqldatareaderThank you for helping! I was hoping to get an answer if its possible to make the sqlreader work for several Forms at the same time, and if so how?
-
Need help with SqldatareaderHi im new to Both C# and sql and exept from that my problem is: I´ve managed to connect to a mssql database (express edition) from my C# program and I have the sqldata reader to read my question to listboxes in my windowsForm. Ive understood from "Beginners guide to accessing SQL Server through C#" that once you got your connection running and the reader has read the table in the database You can rephrase your question without reading directly to the database. If that is correct, Is it possible to establish a connection to the sql database in "program.cs" and get your reader to read the whole table and then let different windowsForms make sql questions to that reader? Im hoping to gain less questions to the DB and its supposed to get the table every five minutes or something. I would be very happy if anyone could help me in this matter Here is an example of code in my Form:
public partial class BinMonitor : Form { private SqlConnection conn; private SqlCommand cmd; private SqlDataReader reader; string Sql; public BinMonitor() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } // Gets the actual time and returns to a textbox private void timer1_Tick(object sender, EventArgs e) { textBox1.Text = DateTime.Now.ToLongTimeString(); } //gets values from DB once a minute private void timer2_Tick(object sender, EventArgs e) { listBox1.Items.Clear(); listBox2.Items.Clear(); listBox3.Items.Clear(); string connStr = "server=DBserver; user id=user; password=pwd; database=flights;Trusted_Connection=yes;"; SqlConnection conn = new SqlConnection(connStr); conn.Open(); reader = null; cmd = new SqlCommand("SELECT * FROM BinMonitor Where Departure !<" + "'" + textBox1.Text + "'" + "order by Departure ASC", conn); reader = cmd.ExecuteReader(); reader.Read(); while (reader.Read()) { listBox1.Items.Add(reader.GetString(0)); listBox2.Items.Add(reader.GetString(1)); listBox3.Items.Add(reader.GetString(2)); } } } }
Lost in space