我無法將一個值從一個類傳遞到另一個,當我嘗試時,值傳遞爲0而不是第一個類的值。我無法將一個值從一個類傳遞到另一個
我有這樣的一種方法,它將檢查人員是否在數據庫中,並且變量IDautor將獲得該ID在數據庫中,它將進入if子句,然後位置1中的數組id2將會拯救IDautor價值......我假裝用在類Artigo該值,但該值來始終爲0,我不無爲什麼 類作者日期
public bool Login(TextBox txtUser, TextBox txtPassword)
{
string utl, pass;
try
{
utl = txtUser.Text;
pass = txtPassword.Text;
_Sql = "Select Count(IDAutor) From Autor Where uUser = @uUser and Pass = @Pass";
SqlCommand cmd = new SqlCommand(_Sql, Conn);
cmd.Parameters.Add("@uUser", SqlDbType.VarChar).Value = utl;
cmd.Parameters.Add("@Pass", SqlDbType.VarChar).Value = pass;
Conn.Open();
IDautor = (int)cmd.ExecuteScalar();
if (IDautor > 0)
{
MessageBox.Show("Bem Vindo");
Conn.Close();
id2[1] = IDautor;
return true;
}
else
{
MessageBox.Show("Tera que tentar de novo");
Conn.Close();
return false;
}
}
catch(Exception ex)
{
MessageBox.Show("ERRO Message: "+ ex);
Conn.Close();
return false;
}
}
public int[] id2
{
get { return this.id2; }
}
,並在試圖拯救值array id2並在另一個類中使用該值
Class Artigo
public string AddArtigo(string newArtigo)
{
if (newArtigo == null)
{
return "Nao selecionou o PDF desejado. Tente de novo";
}
if (newArtigo != null)
{
using (FileStream st = new FileStream(newArtigo, FileMode.Open, FileAccess.Read))
{
SqlConnection Conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Convidado1\Desktop\Aplicaçao C#\Aplicaçao\ITArtiConf\ITArtiConf\Database1.mdf;Integrated Security=True;User Instance=True");
Autor au = new Autor();
byte[] buffer = new byte[st.Length];
st.Read(buffer, 0, (int)st.Length);
st.Close();
Conn.Open();
SqlCommand cmd = Conn.CreateCommand();
cmd.CommandText = "insert into Artigo (idAutor) values('" + au.id2[1] + "')";
cmd.ExecuteNonQuery();
Conn.Close();
SqlCommand cmd1 = new SqlCommand("UPDATE SomeTable SET [email protected] WHERE idAutor =" + au.id2[1], Conn);
cmd1.Parameters.AddWithValue("@Artigo", buffer);
Conn.Open();
int i = cmd1.ExecuteNonQuery();
Conn.Close();
}
return "Guardado";
}
return "Error";
}
au.id2 [1]變成了0而不是另一個類中的值。
該陣列是我有一些愚蠢的想法,並使用文本框是保存代碼行...但謝謝... –