Hello
I'm trying to develop a text-based rpg game in C# using sql express in C# 2008 express. I'm still trying to figure out if the way that I want to develop the application is possilbe/reasonable.
- use a richtext box and buttons for dialog and controls.
- manage the sqlexpress connection using code not controls.
- use a class structure to make the SqlConnection methods/members available to all controls on a form, as opposed to defining a new instance of the connection for every control.
Googling has given a number of console-oriented solutions, but nothing for windows forms that has matched. The closest I found demonstrated all of the connection activity being repeated per control.
what I've managed to get put together so far is very little.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
namespace Trpg { public partial class TRPG : Form { //inserting class for sql connect here public class Connect { SqlConnection tconnect;
public object TRPGConnect() { tconnect = new SqlConnection(@"server = .\sqlexpress;integrated security = true ;database = trpg"); return tconnect; } } //end of sql connect class here
// create an instance of the connection. Connect trpgc = new Connect();
public TRPG() { InitializeComponent(); }
private void btnExit_Click(object sender, EventArgs e) { Application.Exit(); }
private void TRPG_Load(object sender, EventArgs e) {
} public void testConnect() { tconnect.Open(); tconnect.Close(); } } }
|
The error message I get is "error CS0103: The name 'tconnect' does not exist in the current context". I take it that is a scope issue, but I don't understand where my error is.
Any help is very much appreciated. I will keep looking to see if I can figure it out.
naura paxPosted Oct 2, 2009, 1:10 AM
you can modify your testConnect method like this:
And by the way, you should create your TRPGConnect class as inner class of your form. Instead create it separately in some other file or if possible in other project and reference that project as a library in your window project.
You google about Data Access Layer for further understanding.
please mark as answered if useful.
Collins GarlinnPosted Oct 2, 2009, 1:15 PM
This will help quite a bit, both in learning as well as this project. Thank you.