Program With Multi language support
-
Hi all i created a database and table for language and translations the fileds are like this
language-> languagename,languagecode English 101 Hindi 102 translation-> textinenglish,languagecode,translated Hellow 101 Hellow Hellow 102 hindihellow
Now I Have A Combo box in my form and 1 label I Need To Change label text to the selected language in combobox so i writed code like this but i dont know how to get the value from database Please Help meSqlConnection con = new SqlConnection("server=ARUN-09BF105DE8\\AR; initial catalog=prod; integrated security=true");
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
object scode;
scode = comboBox1.SelectedValue;
changelanguage(scode);
}
public void changelanguage(object code) {
con.Open();
SqlCommand com = new SqlCommand();
SqlDataReader dr;
com.Parameters.AddWithValue("language", code);
com.CommandText = "SELECT translated FROM translation WHERE languagecode=@language";
dr=com.ExecuteReader();}
Trust one who has tried
-
Hi all i created a database and table for language and translations the fileds are like this
language-> languagename,languagecode English 101 Hindi 102 translation-> textinenglish,languagecode,translated Hellow 101 Hellow Hellow 102 hindihellow
Now I Have A Combo box in my form and 1 label I Need To Change label text to the selected language in combobox so i writed code like this but i dont know how to get the value from database Please Help meSqlConnection con = new SqlConnection("server=ARUN-09BF105DE8\\AR; initial catalog=prod; integrated security=true");
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
object scode;
scode = comboBox1.SelectedValue;
changelanguage(scode);
}
public void changelanguage(object code) {
con.Open();
SqlCommand com = new SqlCommand();
SqlDataReader dr;
com.Parameters.AddWithValue("language", code);
com.CommandText = "SELECT translated FROM translation WHERE languagecode=@language";
dr=com.ExecuteReader();}
Trust one who has tried
If you look here: http://stackoverflow.com/questions/119568/best-practice-to-make-a-multi-language-application-in-c-winforms[^] there is a discussion of the various ways to achieve this. The way you have selected is not necessarily the best: it requires a version of SQLServer to be available to each PC on which your app will run, which may not be possible or desirable. However:
public void changelanguage(object code) { con.Open(); SqlCommand com = new SqlCommand(); SqlDataReader dr; com.Parameters.AddWithValue("language", code); com.CommandText = "SELECT translated FROM translation WHERE languagecode=@language"; dr=com.ExecuteReader(); while (dr.Read()) { if ((string) dr\["textinenglish"\] == theWordIWantToTranslate) { ... } } }
BTW: Please remember that you are responsible for Close-ing and Dispose-ing all of the SQLCommand and SQLConnection objects you create!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."
-
Hi all i created a database and table for language and translations the fileds are like this
language-> languagename,languagecode English 101 Hindi 102 translation-> textinenglish,languagecode,translated Hellow 101 Hellow Hellow 102 hindihellow
Now I Have A Combo box in my form and 1 label I Need To Change label text to the selected language in combobox so i writed code like this but i dont know how to get the value from database Please Help meSqlConnection con = new SqlConnection("server=ARUN-09BF105DE8\\AR; initial catalog=prod; integrated security=true");
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
object scode;
scode = comboBox1.SelectedValue;
changelanguage(scode);
}
public void changelanguage(object code) {
con.Open();
SqlCommand com = new SqlCommand();
SqlDataReader dr;
com.Parameters.AddWithValue("language", code);
com.CommandText = "SELECT translated FROM translation WHERE languagecode=@language";
dr=com.ExecuteReader();}
Trust one who has tried
Arunkumar.Koloth wrote:
AddWithValue("language",
Don't forget the
@
. And, yeah, that doesn't look like the best way to do it. -
Arunkumar.Koloth wrote:
AddWithValue("language",
Don't forget the
@
. And, yeah, that doesn't look like the best way to do it.can you tell me a good way to do this?
-
can you tell me a good way to do this?
No, I've never done it.