|
Better... but it's a directive, not a statement.
|
|
|
|
|
fixed that too. Thanks.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi all
i created a database and table for language and translations
the fileds are like this
<br />
language-><br />
languagename,languagecode<br />
English 101<br />
Hindi 102<br />
<br />
translation-><br />
textinenglish,languagecode,translated<br />
Hellow 101 Hellow<br />
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 me
SqlConnection 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."
|
|
|
|
|
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?
|
|
|
|
|
|
how can we do the database connectivity in c# windows form
|
|
|
|
|
Take your pick:
ADO.NET
Enitiy Framework
LINQ to SQL
nHibernate.
|
|
|
|
|
Keith Barrow wrote: Take your pick
That will only be helpful if he is data mining, surely?
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."
|
|
|
|
|
I've never been accused of being helpful yet
|
|
|
|
|
|
a) Don't -- never put data access in your UI layer.
b) Once you have a Data Access Layer -- access it from your UI layer.
|
|
|
|
|
do it like this..
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
namespace Access
{
public class Connection
{
private string getConnectionString()
{
return "connetionString";
}
public static void ExecuteCommand(string command)
{
OleDbConnection con;
OleDbCommand com;
try
{
con = new OleDbConnection(getConnectionString());
con.Open();
com = new OleDbCommand(command);
com.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
}
}
//Call Connection Method
public void MyMethord()<br />
{<br />
Connection.ExecuteCommand("command write here");<br />
}
|
|
|
|
|
public void connection()
{
con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=practice;Data Source=HOME-78F3176757");
con.Open();
}
public DataSet filldata(string mystring)
{
connection();
adp = new SqlDataAdapter(mystring, con);
ds = new DataSet();
adp.Fill(ds);
return ds;
}
|
|
|
|
|
Hi experts,
I am under the impression that .NET programs (C# with VisualStudio 2008) always compile to an executable (programname.exe ) and a settings file (programname.exe.config ). Sometimes there is more to a program, but these two persist. They end up being in the same directory.
I logged on to a WinXP Prof as Admin and installed a .NET program. This program allows to store some data in its programname.exe.config file, which resides in %PROGRAMFILESFOLDER%/Programname/ anlongside with programname.exe .
To 'store' means to
Properties.Settings.Default.MyIntValue = 25;
Properties.Settings.Default.Save();
here.
I ran the program, it worked as expected. Then I logged out and back on as restricted user. The program still worked like a charm.
If I understand correctly, changing and saving in Settings.Default.* is achieved by changing programname.exe.config . How can it be that restricted user is allowed to do so? He's not allowed to change any file through notepad.
And, will this stay possible in Windows Vista and 7?
Or will I have to re-direct the settings file somehow to some %APPSETTINGS% directory for those?
Ciao,
luker
|
|
|
|
|
You cannot. It resides on users computer and he can change the file. One of the options is to get rid of the setting itself. If it is an important value, why keep it in open?
Settings are to make the application configurable which you do not want.
|
|
|
|
|
Hi,
there are two kinds of settings.
1.
Application settings are the same for all users, and they cannot be changed by the app itself. Those are stored in the appname.exe.config file. You can edit the file with e.g. WordPad, other than that the information could as well have been stored inside the exe file itself.
2.
User settings are individual, they can be changed by the app itself. Those are stored twice: the default value is present in the appname.exe.config file (just like app settings), and it is read-only; the actual value chosen by the user however is stored in a similar file (named user.config ) in a subfolder of the user's personal folder (that is under Documents and Settings on older Windows versions, and under Users since Vista).
So file appname.exe.config can be write protected, no problem; the user's folders should be (and normally are) fully accessible by their owner.
It is of course explained in the MSDN documentation, starting here[^].
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks a lot, Luc.
You have enlightened what was one of universe's mysteries to me for months.
And, of course MSDN features an article on the topic, but it focuses on how to use settings while leaving out how the framework achieves this behaviour. Thank you for your additional information.
Ciao,
luker
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi can anyone tell me, how to bind a data to class objects from a list, so that i can pass it in xml request..
here is my code in xsd generated class.
<pre>public partial class SetValue
{
private string dANameField;
private string dAIDField;
private SetValueType setValueTypeField;
public string DAName
{
get
{
return this.dANameField;
}
set
{
this.dANameField = value;
}
}
public string DAID
{
get
{
return this.dAIDField;
}
set
{
this.dAIDField = value;
}
}
public SetValueType SetValueType
{
get
{
return this.setValueTypeField;
}
set
{
this.setValueTypeField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://xml.abc.com/ns/msjava/lrm")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://xml.abc.com/ns/msjava/lrm", IsNullable = false)]
public partial class SetValueType
{
private string valueTypeIDField;
private string valueTypeField;
private string valueField;
private Function functionField;
private Field fieldField;
public string ValueTypeID
{
get
{
return this.valueTypeIDField;
}
set
{
this.valueTypeIDField = value;
}
}
public string ValueType
{
get
{
return this.valueTypeField;
}
set
{
this.valueTypeField = value;
}
}
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
public Function Function
{
get
{
return this.functionField;
}
set
{
this.functionField = value;
}
}
public Field Field
{
get
{
return this.fieldField;
}
set
{
this.fieldField = value;
}
}
}</pre>
here i have to do something, so that i can add the data in this list to class type(SetValueType), so that later i will convert it into xml format..
<pre> SetValue DAESetvalue = new SetValue
{
DAID=oSetValue.DAID,
DAName=oSetValue.DAName
};
DADirective.SetValue = DAESetvalue;
List<SetValueType> SetValueTypeList = new List<SetValueType>();
GetValueTypeCondition(gValueTypeCondition,SetValueTypeList);
public void GetValueTypeCondition(Grid gValueTypeCondition,List<SetValueType> SetValueTypeList)
{
int rowcount = 0;
if (gValueTypeCondition.RowDefinitions != null)
rowcount = gValueTypeCondition.RowDefinitions.Count;
for (int i = 0; i < rowcount; i++)
{
SetValueType oSetValueType = new SetValueType();
foreach (UIElement element in gValueTypeCondition.Children.Cast<UIElement>().Where(element => Grid.GetRow(element) == i))
{
if (element is ComboBox)
{
ComboBox cbvaluetype = (ComboBox)element;
if (cbvaluetype.Uid != null)
{
Object obj = ((ComboBoxItem)(cbvaluetype.SelectedItem)).Tag;
if (obj != null)
{
if (cbvaluetype.Uid == DataKey.FUNCTION_KEY)
{
DAFunction dafunction = (DAFunction)obj;
oSetValueType.ValueTypeID = "2";
oSetValueType.ValueType = "Function";
oSetValueType.Function.FunctionID = dafunction.FunctionID;
oSetValueType.Function.FunctionName = dafunction.FunctionName;
oSetValueType.Function.DataType1 = dafunction.DataType1;
oSetValueType.Function.DataType2 = dafunction.DataType2;
oSetValueType.Function.DataType3 = dafunction.DataType3;
}
else if (cbvaluetype.Uid == DataKey.COLUMN_CONDITION_KEY)
{
DAColumn dacobj = (DAColumn)obj;
oSetValueType.ValueTypeID = "3";
oSetValueType.ValueType = "Field";
oSetValueType.Field.FieldID = dacobj.id;
oSetValueType.Field.FieldValue = dacobj.name;
}
}
}
}
else if (element is TextBox)
{
TextBox txtValueType = (TextBox)element;
switch (txtValueType.Uid)
{
case DataKey.TEXT_VALUE_KEY:
oSetValueType.ValueTypeID = "1";
oSetValueType.ValueType = "Value";
oSetValueType.Value = txtValueType.Text.Replace("_", "").Trim();
break;
case DataKey.TEXT_FUNCTION_VALUE_KEY:
oSetValueType.Function.FunctionValue = txtValueType.Text.Replace("_", "").Trim();
break;
}
}
}
SetValueTypeList.Add(oSetValueType);
}
}</pre>
so any help like how to do it...
|
|
|
|
|
Hi,
I want to remove "Back-Slashes \" from string.
Kindly note the following example.
string strText = "(0,2,\"\",\"113.07\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\")";
Thank you
|
|
|
|
|
try the String replace method
this is the MSDN for it
|
|
|
|
|
I tried following method but it does'nt work.
strText = strText.Replace('\',String.Empty);
strText = strText.Replace(('\').ToString(),String.Empty);
|
|
|
|
|
You need to use the double backslash (single backslash in a string is the escape mark) and also use a String rather than character, thus:
strText = strText.Replace(("\\"), String.Empty);
See here[^] for full details.
The best things in life are not things.
|
|
|
|