PDA

View Full Version : سوال: کار با dll



itgirl20
چهارشنبه 12 اسفند 1388, 12:39 عصر
من از db_dll استفاده کردم اما در قسمت db connection به مشکل برخوردم



privatevoid btnIns_Click(object sender, EventArgs e)
{
int grp;
if (cmbGrp.SelectedItem.ToString() == "ê¢ه©çى")
grp = 0;
else
grp = 1;
if (txtMob.Text.Length > 0 && cmbGrp.Text.Length > 0)
{
string cnStr = "Data Source = " + System.Net.Dns.GetHostName() + ";Initial Catalog = Northwind;;Integrated Security = true";
if (DB.dbConnected(cnStr))
{
DB myDB = newDB();
string insCmd = "Insert into customer(ID,Name,Family,Phone_number) values('" + grp + "','" + txtName.Text + "','"+txtFamily.Text+"','"+txtMob.Text+"')";
MessageBox.Show(myDB.insert(cnStr, insCmd));
fillDgView();

}
else
{
MessageBox.Show("Connection failed." + Environment.NewLine + "Check your connection string.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
MessageBox.Show("Information not complete.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}


}

Vahid_moghaddam
چهارشنبه 12 اسفند 1388, 12:48 عصر
می شه یه مقدار واضح تر بگید؟ db_dll چی هست و چه پیغام خطایی می گیرید؟

SMRAH1
چهارشنبه 12 اسفند 1388, 12:51 عصر
سلام
1) db_dll چیه؟
2) دقیقا مشکل چیه (اگر خطا است،متن خطا چیه و اگر در کامپایل است کدام خط،اگر در دیباگ است کدام خط و. ...)
موفق باشید

itgirl20
چهارشنبه 12 اسفند 1388, 14:23 عصر
من dll برنامه رو از این لینک دانلود کردم

http://barnamenevis.org/forum/showpost.php?p=348253&postcount=18

برنامه مشکلی نداره فقط خطای connection string میده (connection failed)
با تشکر

SMRAH1
چهارشنبه 12 اسفند 1388, 19:43 عصر
سلام
باید ConnectionString رو درست کنی ( توی متغیر cnStr ذخیره شده).
موفق باشید

m.developer
چهارشنبه 12 اسفند 1388, 22:51 عصر
ببخشيد منظورت از اينكه مي گين درست كنين چيه آخه كدش كه مشكلي نداره . من بدون Dll ميتونم به بانك وصل شم اما با Dll نميتونم چرا؟:ناراحت:

gerdioz
پنج شنبه 13 اسفند 1388, 15:56 عصر
مشکل شما dll نیست Connection String شما از نظر نوشتاری مورد دارد اگر مسیر شما آدرس یک کامپیوتر دیگه در شبکه است باید پیزی شبیه این نوشته شود
connectionString="Data Source=192.168.0.10;Initial Catalog=Trace;Integrated Security=True;User ID=sa;Password=sqlserver":متعجب:

FastCode
پنج شنبه 13 اسفند 1388, 16:04 عصر
reflector:

public class DB
{
// Methods
public static bool dbConnected(string ConnectionString)
{
SqlConnection connection = new SqlConnection(ConnectionString);
try
{
connection.Open();
connection.Close();
return true;
}
catch (Exception)
{
return false;
}
}

public string delete(string ConnectionString, string DeleteCommand)
{
try
{
SqlConnection connection = new SqlConnection(ConnectionString);
SqlCommand command = new SqlCommand(DeleteCommand, connection);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
return "Delete successful.";
}
catch (Exception exception)
{
return exception.StackTrace.ToString();
}
}

public string insert(string ConnectionString, string InsertCommand)
{
try
{
SqlConnection connection = new SqlConnection(ConnectionString);
SqlCommand command = new SqlCommand(InsertCommand, connection);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
return "Insert 1 record successful.";
}
catch (Exception exception)
{
return exception.StackTrace.ToString();
}
}

public DataSet select(string ConnectionString, string SelectCommand)
{
SqlConnection selectConnection = new SqlConnection(ConnectionString);
SqlDataAdapter adapter = new SqlDataAdapter(SelectCommand, selectConnection);
DataSet dataSet = new DataSet();
selectConnection.Open();
adapter.Fill(dataSet);
selectConnection.Close();
return dataSet;
}

public string update(string ConnectionString, string UpdateCommand)
{
try
{
SqlConnection connection = new SqlConnection(ConnectionString);
SqlCommand command = new SqlCommand(UpdateCommand, connection);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
return "Update successful.";
}
catch (Exception exception)
{
return exception.StackTrace.ToString();
}
}
}

نظر شما راجع به این کد hypercomputing چیه؟

m.developer
جمعه 14 اسفند 1388, 09:45 صبح
ممنون كه جواب دادين CONNECTION STRING مشكل داشت كه درستش كردم :چشمک: