OK, I got it. I'll show you here how I solved it:
I made a new class named Map:
csharp
class Map
{
private string[] MapNames;
private int[] MapIDs;
public Map()
{
string sLine;
StreamReader sr = new StreamReader("maps.txt");
string[] MapNames = new string[1221];
int[] MapIDs = new int[1221];
for (int i = 0; i < 1221; i++)
{
sLine = sr.ReadLine();
string[] content = sLine.Split(new char[] { '\t' });
MapIDs[i] = int.Parse(content[0]);
MapNames[i] = content[1];
}
sr.Close();
this.MapIDs = MapIDs;
this.MapNames = MapNames;
}
public string GetMapNameByIndex(int index)
{
return this.MapNames[index];
}
public int GetMapIDByIndex(int index)
{
return this.MapIDs[index];
}
public int GetMapIDByName(string name)
{
for (int m = 0; m < 1221; m++)
{
if (this.MapNames[m].Equals(name))
return MapIDs[m];
}
return 0;
}
public string GetMapNameById(int id)
{
for (int m = 0; m < 1221; m++)
{
if (this.MapIDs[m].Equals(id))
return MapNames[m];
}
return "";
}
public int GetIndexByID(string id)
{
for (int m = 0; m < 1221; m++)
{
if (this.MapIDs[m].ToString().Equals(id))
return m;
}
return 0;
}
}
Now, I created a new SQL Query manually, Which returns the Map ID of a charcater, which takes a character ID parameter.
Now, in my search button clicked event I put this code:
csharp
private void CharSBTN1_Click(object sender, EventArgs e)
{
try
{
charactersTableAdapter1.FillBy(gameDataSet1.characters, SearchBox.Text);
this.IDBox.Visible = true;
this.NameBox.Visible = true;
this.MoneyBox.Visible = true;
this.comboBox1.Visible = true;
this.button1.Visible = true;
string t = charactersTableAdapter1.GetMapbyID(IDBox.Text).ToString();
this.comboBox1.SelectedIndex = Map.GetIndexByID(t);
this.Size = new System.Drawing.Size(351, 193);
}
catch (SystemException ex)
{
this.comboBox1.SelectedItem = null;
MessageBox.Show("Not Exist!");
}
}
There, Now it shows the map the chacter is on. But how can I change it? I got stuk here for a couple of minutes, thinking about binding but then I thought about making another query!
Now, here's the code on my save button click event:
csharp
private void button1_Click(object sender, EventArgs e)
{
try
{
int mapi = Map.GetMapIDByIndex(comboBox1.SelectedIndex);
charactersTableAdapter1.UpdateLim(NameBox.Text, mapi, int.Parse(MesoBox.Text), int.Parse(IDBox.Text));
MessageBox.Show("SAVED!", "Char edit mode");
}
catch (SystemException ex)
{
MessageBox.Show("Fuck you Idiot!"); //Temp LOL
}
}
There! That's how I solved it!
Those are my query if you want to see it:
The Table Adapter filling query:
sql
SELECT ID, name, userid, world_id, level, job, str, dex, `int`, luk, chp, mhp, cmp, mmp, hpmp_ap, ap, sp, exp, fame, map, pos, gender, skin, eyes, hair, mesos,
buddylist_size, online
FROM characters
WHERE (name = @name)
The map getting query:
sql
SELECT map
FROM characters
WHERE (ID = @ID)
And the updating query, used in the save button:
sql
UPDATE characters
SET name = @name, map = @map, mesos = @mesos
WHERE (ID = @Original_ID)
Well, I hope my solution is good, but if you got anything to say, say it!
This post has been edited by MaxMow: 3 Jul, 2008 - 12:23 AM