Erro apresentado (esse erro dá no DataTable dtb, quando eu tento executar):
System.IndexOutOfRangeException was unhandled
Message="Não há linha na posição 1."
Source="System.Data"
StackTrace:
em System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)
em System.Data.RBTree`1.get_Item(Int32 index)
em System.Data.DataRowCollection.get_Item(Int32 index)
em SisAr.frmFichas.btnCadastra_Click(Object sender, EventArgs e) na C:\Documents and Settings\Baroni\Meus documentos\Visual Studio 2008\Projects\SisAr\SisAr\frmFichas.cs:linha 399
em System.Windows.Forms.Control.OnClick(EventArgs e)
em System.Windows.Forms.Button.OnClick(EventArgs e)
em System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
em System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
em System.Windows.Forms.Control.WndProc(Message& m)
em System.Windows.Forms.ButtonBase.WndProc(Message& m)
em System.Windows.Forms.Button.WndProc(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
em System.Windows.Forms.Application.Run(Form mainForm)
em SisAr.Program.Main() na C:\Documents and Settings\Baroni\Meus documentos\Visual Studio 2008\Projects\SisAr\SisAr\Program.cs:linha 17
em System.AppDomain._nExecuteAssembly(Assembly assembly, String[]args)
em System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
em System.Threading.ThreadHelper.ThreadStart_Context(Object state)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
Pergunta
hencker
Bom dia!
Tenho a seguinte SP no meu banco:
E estou usando o seguinte código para acessar a SP:public DataTable AdicionaRegistro(string NATUREZA, string FOLHA, string LIVRO, string ABERTURA, string ENCERRAMENTO, string SE, string DATA) { SqlCommand command = new SqlCommand("RetornaID", conSisAr); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@NATUREZA", SqlDbType.Int, 4, "NATUREZA_ID").Value = NATUREZA.ToString(); command.Parameters.Add("@FOLHA", SqlDbType.Char, 5, "FOLHA").Value = FOLHA.ToString(); command.Parameters.Add("@LIVRO", SqlDbType.Char, 5, "LIVRO").Value = LIVRO.ToString(); command.Parameters.Add("@ABERTURA", SqlDbType.Char, 1, "ABERTURA").Value = ABERTURA.ToString(); command.Parameters.Add("@ENCERRAMENTO", SqlDbType.Char, 1, "ENCERRAMENTO").Value = ENCERRAMENTO.ToString(); command.Parameters.Add("@SE", SqlDbType.Char, 1, "SE").Value = SE.ToString(); command.Parameters.Add("@DATA", SqlDbType.Char, 10, "DATA").Value = DATA.ToString(); SqlParameter parameter = command.Parameters.Add("@Identity", SqlDbType.Int, 0, "ID"); parameter.Direction = ParameterDirection.Output; try { conSisAr.Open(); SqlDataAdapter adapter = new SqlDataAdapter(command); DataTable dt = new DataTable(); adapter.Fill(dt); return dt; } finally { conSisAr.Close(); } }No entanto quando eu uso o método abaixo para recuperar os dados o resultado é nulo (dt não restorna nenhum valor...)Erro apresentado (esse erro dá no DataTable dtb, quando eu tento executar):
Alguém poderia dar alguma luz?
Link para o comentário
Compartilhar em outros sites
2 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.